The particle system in three.js is stationary and unable to move

After delving into a Chinese book on WebGL, I decided to test out the particle system example in Firefox. However, I encountered an issue where my particles were not moving as expected.

I have uploaded my source code and resources to the following website:

Upon checking the browser console logs, I found the following messages:

"THREE.WebGLRenderer" "75"

three.min.js:631:0 "THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead."

three.min.js:791:67 "THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial."

three.min.js:777:230 "THREE.ParticleSystem has been renamed to THREE.Points."

three.min.js:769:197 "THREE.WebGLRenderer: image is not power of two (109x109). Resized to 128x128"

Here is a snippet from the HTML file's code:

function updateParticles(){

   var particleNum = particleSystem.geometry.vertices.length;

   for(var i=0; i<particleNum; i++){
       particle = particleSystem.geometry.vertices[i];
       particle.z +=  5;       
       if(particle.z>1000){
          particle.z-=2000;
       }
   }
}


function animate() {

   requestAnimationFrame(animate);

   updateParticles();

   renderer.render(scene, camera);
}

If anyone could offer assistance in resolving this problem, it would be greatly appreciated. Thank you!

Answer №1

It appears that you may be using an outdated version of three.js which is causing issues with the particle system implementation. Here is a demonstration similar to your project. Running this sample locally works fine, but when substituting it with the three.min.js from your work, it stops functioning correctly. You can download the three.js version used in the example here.

// @see http://paulirish.com/2011/requestanimationframe-for-smart-animating/
window.requestAnimFrame = (function(){
   return  window.requestAnimationFrame       ||
           window.webkitRequestAnimationFrame ||
           window.mozRequestAnimationFrame    ||
           window.oRequestAnimationFrame      ||
           window.msRequestAnimationFrame     ||
           function(/* function */ callback, /* DOMElement */ element){
              window.setTimeout(callback, 1000 / 60);
           };
 })();
// set the scene size
var WIDTH = 400,
        HEIGHT = 300;

// define camera attributes
var VIEW_ANGLE = 45,
        ASPECT = WIDTH / HEIGHT,
        NEAR = 0.1,
        FAR = 10000;

// get the container element
var $container = $('#container');

// create WebGL renderer, camera, and scene objects
var renderer = new THREE.WebGLRenderer();
var camera = new THREE.Camera( VIEW_ANGLE,
        ASPECT,
        NEAR,
        FAR );
var scene = new THREE.Scene();

// position the camera away from origin
camera.position.z = 300;

// initialize the renderer with black background
renderer.setClearColor(new THREE.Color(0, 1));
renderer.setSize(WIDTH, HEIGHT);

// attach renderer's DOM element
$container.append(renderer.domElement);

// define particle variables
var particleCount = 1800,
        particles = new THREE.Geometry(),
        pMaterial = new THREE.ParticleBasicMaterial({
           color: 0xFFFFFF,
           size: 20,
           map: THREE.ImageUtils.loadTexture(
                   "./Images/icon_ch.png"
           ),
           blending: THREE.AdditiveBlending,
           transparent: true
        });

// generate individual particles
for(var p = 0; p < particleCount; p++) {

   var pX = Math.random() * 500 - 250,
           pY = Math.random() * 500 - 250,
           pZ = Math.random() * 500 - 250,
           particle = new THREE.Vertex(
                   new THREE.Vector3(pX, pY, pZ)
           );

   particle.velocity = new THREE.Vector3(
           0,             
           -Math.random(),    
           0);                

   particles.vertices.push(particle);
}

// create the particle system
var particleSystem = new THREE.ParticleSystem(
        particles,
        pMaterial);

particleSystem.sortParticles = true;

// add particle system to the scene
scene.addChild(particleSystem);

// animation loop
function update() {

   particleSystem.rotation.y += 0.01;

   var pCount = particleCount;
   while(pCount--) {

       var particle = particles.vertices[pCount];

       if(particle.position.y < -200) {
           particle.position.y = 200;
           particle.velocity.y = 0;
       }

       particle.velocity.y -= Math.random() * .1;

       particle.position.addSelf(
               particle.velocity);
   }

   particleSystem.geometry.__dirtyVertices = true;

   renderer.render(scene, camera);

   requestAnimFrame(update);
}
requestAnimFrame(update);

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

Is there a way to submit the value of a textbox that has been generated dynamically using jQuery?

I am currently using the CodeIgniter framework and am attempting to incorporate textboxes in an HTML form. When the user clicks a button, a new textbox should be generated automatically using jQuery. However, when I submit the form, the values of the dynam ...

Tips for replicating a directive with isolated scopes

Is there a way to transfer the text entered in my directives to $scope.output = [] when using ng-submit? Take a look at the live code: JSFiddle I've developed an anchor and attribute directive <a href="" data-clicker>add section</a> that ...

Request validated even though _RequestVerificationToken was not included in the AJAX request

Implementing HtmlAntiForgeryToken in an MVC application involves adding @Html.AntiForgeryToken() on the .cshtml page and including the [ValidateAntiForgeryToken] attribute in the controller. When making an AJAX POST call to the controller, it is crucial to ...

Are top-level script blocks being executed multiple times?

I am perplexed by the strange behavior I am experiencing with my ASP.Net website. In the rendered HTML, a script block is causing an alert that should run once to actually run twice. It seems like there are two separate threads running the same code in Chr ...

Leveraging Iterated Variable Names for Basic Calculations Within a JavaScript for Loop

I am encountering difficulties in creating and manipulating variables dynamically within a loop. Specifically, I need to create variable names in a loop and then perform simple math operations on them. Despite my efforts, these variables are being recogniz ...

Progress Circles on Canvas in FireFox

Currently, I am experimenting with this codepen demo that utilizes canvas to generate progress circles: The functionality functions perfectly in Chrome and Safari; however, it only displays black circles in FireFox. My knowledge of canvas is limited, so I ...

Applying the has-error class dynamically in AngularJS to enhance input field styling

I have a scenario where HTML is being dynamically generated from JSON, and I am looking to incorporate validation logic into the process. For better understanding, here is an example snippet: <div ng-switch on="field.type" ng-hide="{{ field.hide }}"& ...

Will Angular 2 be taking over from traditional AngularJS or will it simply provide another option?

Considering the shift from Angular 1's MVC architecture to Angular 2's component-based structure, it seems like migrating between these versions would necessitate a significant amount of refactoring. Unless there are unforeseen factors at play? ...

Ways to decrease and transform a collection of objects?

What is the best way to condense and transform this object array into a new array? Here is the data I am working with: var objArray = [{ state: 'NY', type: 'A', population: 100 }, { state: 'NY', ty ...

Apply a chosen style to the element that was clicked on, while removing the style from the rest

Here is an example of my ul li structure: <div id="categoryTree"> <ul> <li id="cat_15"> <a class="hasSubCat" href="javascript:void(0);"><img src="images/icons/folder.gif" border="0" alt="Folder" title=" Folder ">N ...

Retrieve the place_id associated with the address components

Having trouble obtaining the place_id of address_components using Google place autocomplete? The JSON data only includes long_name, short_name, and types. Take a look at my code snippet below: var object_location = document.getElementById('object_loc ...

Avoiding double entries in the shopping list using DOM selectors in JavaScript

I have been struggling with preventing duplicate items from being added to a shopping list that I created. Even though I thought the code below would solve the issue, it hasn't been effective so far. My expectation was for the JavaScript code to acces ...

having trouble transferring the password field in PHP to phpMyAdmin

My HTML form collects the user's first name, last name, username, and password. I am trying to upload this data to my local phpMyAdmin, but I'm facing an issue with storing the password in the database. Below is my HTML code: <input type="te ...

Checkbox inputs with activated labels causing double events to fire

Creating round checkboxes with tick marks dynamically and appending them to id="demo" on the click of two buttons that invoke the get(data) method is my current goal. The issue arises when both buttons are clicked simultaneously, as the checkboxes do not ...

Exploring the option of showcasing multiple json_encode data on a pie chart

Hey there! I'm currently utilizing Chart.js to generate a pie chart by retrieving data from the database: <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.min.js"></script> <script> var ctx = document.getE ...

Guidelines for Sorting Objects and Arrays in a JavaScript Array

I have a set of data that needs to be filtered based on specific parameters. While I can successfully filter through the initial value in the array, I am struggling to filter deeper into nested arrays. The dataset is structured as follows: let data = [ ...

The interface remains static even after the property has been modified

There is a function in my codebase called getData() that fetches data from an API. I am trying to call this function from a different component, which I will refer to as MainComponent and AnotherComponent for the sake of clarity: import MainComponent from ...

Exploring the functionality of maximizing and minimizing logic in an Angular Bootstrap modal popup

I'm currently utilizing Angular Bootstrap Modal Popup and I'd like to include options for Maximize and Minimize in addition to the close button. By clicking on the maximize option, the popup should expand to full screen, and by clicking on minimi ...

Use the onclick event to submit a form, ensuring that it can only be submitted once

For a form, I am configuring the action and triggering submission using the onclick event of a div: <div class="action_button" onclick="document.forms['test'].action='url/to/action';document.forms['test'].submit()"> < ...

The AngularJS array data is not displaying correctly

I am having trouble displaying comments array data in HTML properly. The data appears the same as it is in the comments array. What could be causing this issue? How should I proceed? <ul class="media-list" ng-controller="dishDetailController as menuCt ...