Moving a particle along the surface of a sphere using three.js geometry

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 );
      }

Answer №1

When it comes to combining two objects into one, consider utilizing a THREE.Object3D() and making adjustments through that.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Jquery Visualization Chart not displaying

I am struggling to get the jquery visualization to work properly. Although the table and caption appear fine, there is no data showing up in the chart. I've carefully followed the example and searched for any issues, but I can't identify what&apo ...

Ways to troubleshoot the "TypeError: Cannot read property 'value' of null" issue in a ReactJS function

I keep encountering a TypeError: Cannot read property 'value' of null for this function and I'm struggling to pinpoint the source of the issue. Can someone help me figure out how to resolve this problem? By the way, this code is written in R ...

unable to perform a specific binary operation

Is there an efficient method to achieve the following using binary operations? First byte : 1001 1110 Second byte : 0001 0011 Desired outcome : 1000 1100 I am looking to reset all bits in the first byte that correspond to bit values of 1 in the secon ...

What is the best way to retrieve JSON data in ReactJS through ExpressJS?

Exploring the realms of reactjs and expressjs, I am seeking guidance on how to extract data from reactjs and store it in a variable. My current achievement includes successfully executing res.send to display the data. app.get('*', (req, res) =& ...

The add-on for imageminJpegTran is designed to rotate images with ease

When I compress a buffer obtained from a file and rewrite it as a compressed version in memory, I am facing an issue where vertical images are being rotated while square and rectangle images are compressed correctly. Is there a way to pass options to the ...

Adjust the scope variable upon submission and refresh the display in AngularJS

Currently, I am working on my first web app using angularjs and facing an issue where the page does not update with new values once the user submits text or numbers in an input box. For this project, I am utilizing Java8, MongoDB, angularJS, and twitter b ...

Extending a Sub-Object in JavaScript

I'm attempting to include new attributes to the sub-object within object1. However, I am facing issues with it being overwritten. const object1 = { a: 1, b: 2, c: 3, sub: { e: 1, f: 2 } }; const object2 = Object.assign({ j: 4, ...

After integrating Redux into React, the map(item) function is unable to send "item" as props to a JSX component

Currently, I am working on integrating Redux into my React application. As part of this process, I have developed four actions to manage the "items" in my application. The initial three actions, namely GET_ITEMS, DELETE_ITEM, and ADD_ITEM, function seamles ...

Angular input field displaying X

Hey everyone, I'm currently working with Angular and typescript. I have a requirement to hide the first 8 characters that the user enters and only show the remaining 4 characters. Update: I have included a link to the Stackblitz demo Stackblitz <i ...

Unique JQuery CSS dynamic corner scenario

I am faced with a situation where I am dynamically adding a CSS class to a div that contains a flash message using the following line of code: $("div#flash_notice").toggleClass('success'); The JavaScript code is located in the micropost view, ...

Using JSON.stringify to format data and making an asynchronous $http request

I am working with a JavaScript string that looks like this: user_fav = "21,16"; I need to process this string through a function so that it becomes a JSON array with an id key, like this: {"id":21},{"id":16} This JSON array is then used in an $http req ...

What is the process for retrieving the text from a remotely loaded "<script>" element?

I’m currently in the process of developing an AJAX-enabled Manga reader application for Onemanga using Greasemonkey, specifically JS/jQuery. My issue lies in needing to run one of the inline scripts on their page to update the next page URL. My attempte ...

Center a grid of cards on the page while keeping them aligned to the left

I have a grid of cards that I need to align in the center of the page and left within the grid, adjusting responsively to different screen sizes. For example, if there are 10 cards and only 4 can fit on a row due to screen size constraints, the first two ...

How to Dynamically Set AngularJS Filter (like date or currency) Using Variables

When working with Angular, it's possible to easily apply filters to format variables, like so: {{ myDate | date }} {{ myMoney | currency }} But, is there a way to dynamically set the filter type in a more flexible manner as shown below? // controll ...

What could be causing the fourth tab to not show any data while the first three tabs are functioning as expected?

I've encountered an issue with my HTML tabs. While I can easily switch between the first three tabs and view their content, tab 4 doesn't seem to display its associated data. It's puzzling why tab 4 is not working when the others are functio ...

Retrieving a targeted JSON element and adding it to a fresh object

Hello everyone, I have an object that resembles the following structure: [ { "app": 1, "scalable": true, "zoomable": true, "cropBoxResizable": true }, { "app" ...

Ways to recover HTML elements that have been eliminated by jQuery's remove

$(document).ready(function() { $('#remove').click(function() { $('.test').remove(); }); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="test-wra ...

Converting HTML to JSON using jQuery

Currently, I am utilizing the jQuery template plugin to dynamically create HTML based on JSON data that user can then modify (and even change). My goal is to find a way to convert this HTML back into JSON format so that it can be saved back to my server. ...

Unleashing the Power of Lodash Debounce in Vue

Currently, I have integrated debounce from lodash into my main.js file. import lodash from 'lodash' Vue.prototype._ = lodash I've been utilizing it like this._.find(...), and everything has been functioning smoothly. However, when attemptin ...

Optimize Material-UI input fields to occupy the entire toolbar

I'm having trouble getting the material-ui app bar example to work as I want. I've created a CodeSandbox example based on the Material-UI website. My Goal: My goal is to make the search field expand fully to the right side of the app bar, regar ...