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