-1

There are some details about Javascript I am still learning and this is one of them. On line 65 of the linked codepen. "rotationAxis" is added and I am unsure how it was created. I thought at first it was something added through 3js but it's not. You can also change it to just the letter A and it works perfectly fine. Can someone explain the origin of it?

codepen

for ( let i = 0; i < maxParticles; i++ ) {

            let vertex = new THREE.Vector3(20, 0, 0);
            vertex.rotationAxis = new THREE.Vector3(0, Math.random() * 2 - 1, Math.random() * 2 - 1);
            vertex.rotationAxis.normalize();
            vertex.delay = Date.now() + (particlesDelay * i);
            sphereGeometry.vertices.push(vertex);
        }
gman
  • 100,619
  • 31
  • 269
  • 393
Yerbs
  • 127
  • 1
  • 7

1 Answers1

3

JavaScript allows you to add new properties to objects. The property rotationAxis can be named arbitrarily. It's not part of Three.js. The value is accessed later in a call to applyAxisAngle on line 84.

You could think of it like this:

const vector3 = { x: 0, y: 1, z: 2 };
vector3.buzz = 'bazz';
console.log(vector3);

Notice that I didn't need to declare the buzz property anywhere beforehand. I just directly set the property, and the property was created on-the-fly.

4castle
  • 32,613
  • 11
  • 69
  • 106
  • Thanks for the reply, I am so use to reading 3js type of javascript and glsl that I didn't consider the obvious. Nor did I have much experience with this previously, thanks – Yerbs Jun 09 '23 at 20:20