Particle System - Scale X?

Hi All,

I’m trying to figure out a way to Scale the X position of my vertices using a ParticleSystem. I’ve pasted my code below, for reference of my particle system.

var particleSystem;
var particle_system_geometry ;

function createTheVoid()
{
     var numStars = 1000;

     var PI2 = Math.PI * 2;

     particle_system_geometry = new THREE.Geometry();
     particle_system_geometry.verticesNeedUpdate = true;

     var particleMap = new THREE.TextureLoader().load( "./images/star.png" );
     var particle = new THREE.PointsMaterial({map:particleMap, color: 0xffffff, transparent: true, opacity: 1, 
     blending: THREE.AdditiveBlending});

     for (i = 0; i < numStars; i++)
     {
          var vectorThree = new THREE.Vector3(Math.random() * 2 - 1, Math.random() * 2 - 1, Math.random() 
          * 2 - 1);

          particle_system_geometry.vertices.push(vectorThree);
          particle_system_geometry.vertices[i].multiplyScalar(Math.random() * 10 + 450);
    }

     particleSystem = new THREE.Points(particle_system_geometry, particle);
     particleSystem.geometry.verticesNeedUpdate = true;

     scene.add(particleSystem);
     scaleParticles();
}
createTheVoid();

function scaleParticles()
{
     var stars = particleSystem.geometry.vertices;

     for(var i = 0; i < stars.length; i++)
     {
            var star = stars[i];
            // statement below doesn't do anything, why is that?.
            star.scale(2, 0, 0);  
     }
}

Thanks,

  • Abel

I’m curious, have you had a look in you browser console?
For example, when I try to perform your approach like that

var v = new THREE.Vector3(1, 1, 1);
v.scale(2, 0, 0);

I got an error message TypeError: v.scale is not a function. And it’s not surprising, as THREE.Vector3() doesn’t have .scale property or .scale() method. That property belongs to THREE.Object3D().
In your case, you have to call it on your particleSystem. Kind of particleSystem.scale.set(2, 1, 1) or particleSystem.scale.x = 2. And using 0 for scaling y and z will scale your particle system on those dimensions to 0, thus, it’s better to use 1.
And why not to double the random value for x at the time of creation of a vertex? Math.random() * 4 - 2.

1 Like

If you are using THREE.Points you effectively rendering with gl.POINTS. You can only change the diameter of rasterized points with the size parameter of THREE.PointsMaterial. A non-uniform scale is not possible.

1 Like