How can I create lines between adjacent particles in ThreeJS?
I was able to create a particle system for the canvas that was simple and efficient.
Here's a demo: https://awingit.github.io/particles/
Now what I would like to do is create the same in Threejs. However, I have not yet found examples to reference, and I have not been able to create the same as my 2D canvas particle system in 3D.
Can anyone give me some direction as to how I can do this in Threejs?
I know how to work with particles, but what I am struggling with is connecting adjacent dots with lines.
This is how I add the base particles to create the snow / rain effect:
function createSnow() {
for (var i = 0; i < particleCount; i++) {
var pX = Math.random() * 800 - 400,
pY = Math.random() * 700 - 250,
pZ = Math.random() * 800 - 400,
particle = new THREE.Vector3(pX, pY, pZ);
particle.velocity = {};
particle.velocity.y = -1;
particles.vertices.push(particle);
}
particleSystem = new THREE.Points(particles, pMaterial);
particleSystem.position.y = 0;
scene.add(particleSystem);
}
// This goes in the update loop
function animateSnow() {
var pCount = particleCount;
while (pCount--) {
var particle = particles.vertices[pCount];
if (particle.y < -55) {
particle.y = 500;
particle.velocity.y = -1.2;
}
particle.velocity.y -= Math.random() * .02;
particle.y += particle.velocity.y;
}
particles.verticesNeedUpdate = true;
}
So how do I connect between adjacent points?
Any feedback or direction is highly appreciated.
UPDATE: Here's a photo that looks like what I'm hoping to achieve ...
Ignore the shape of the cube, mainly about how the particles have lines connecting adjacent particles.
UPDATE: So I've made some progress. I can create the illusion of separate lines using THREE.LineSegments. It seems like every two vertices are drawing a line. so index 0 and 1 draw the line and then index 2 and 3 draw the line. There is no line between indices 1 and 2.
function addLines(){
var numLines = 10;
var x = 0;
for (nn=0; nn<numLines; nn++)
{
lineGeom.vertices.push(new THREE.Vector3(x, -5, 0));
lineGeom.vertices.push(new THREE.Vector3(x, 5, 0));
x += 5;
}
line = new THREE.LineSegments( lineGeom, lineMaterial );
scene.add(line);
}
I'm a little closer, but the problem I am currently facing is that I cannot apply unique style attributes, for example, I cannot give each line its own style, like width and color. I may need to create separate line objects. See how this progress and share my results ...
source to share
No one has answered this question yet
See similar questions:
or similar: