public void reset(int index) { if (systems == null) { systems = new ParticleSystem[maxStep]; steps = new int[maxStep]; addVelocities = new Vector3[maxStep][particleSize]; } if (systems[index] == null) { // initialize Geometry geometry = THREE.Geometry(); for (int i = 0; i < particleSize; i++) { geometry.vertices().push(THREE.Vector3(0, 0, 0)); } ParticleSystem system = THREE.ParticleSystem(geometry, baseMaterial.build()); // system.setSortParticles(true); systems[index] = system; parent.add(system); } else { // ParticleSystem system = systems[index]; ((ParticleBasicMaterial) system.getMaterial()).setSize(baseSize); for (int i = 0; i < particleSize; i++) { Vector3 vertex = system.getGeometry().vertices().get(i); vertex.set(0, 0, 0); } system.getGeometry().setVerticesNeedUpdate(true); } // addVelocities=new Vector3[maxStep][particleSize]; // simple and boring for (int i = 0; i < particleSize; i++) { addVelocities[index][i] = THREE.Vector3( plusMinus(velocityRange.getX()), plusMinus(velocityRange.getY()), plusMinus(velocityRange.getZ())); } Vector3 addwind = THREE.Vector3( plusMinus(velocityRange.getX()) * 2, plusMinus(velocityRange.getY()) * 2, plusMinus(velocityRange.getZ()) * 2); // wind.addSelf(addwind); if (index % 5 == 0) { wind.set( wind.getX() / 4 * 3 + addwind.getX() / 4, wind.getY() / 4 * 3 + addwind.getY() / 4, wind.getZ() / 4 * 3 + addwind.getZ() / 4); } for (int i = 0; i < particleSize; i++) { winds[i] = THREE.Vector3( plusMinus(velocityRange.getX()) * 5, plusMinus(velocityRange.getY()) * 5, plusMinus(velocityRange.getZ()) * 5); } }
public void update() { if (systems == null || systems[index] == null) { reset(index); } for (int j = 0; j < maxStep; j++) { ParticleSystem system = systems[j]; if (system == null) { break; } Vector3 addAccel = THREE.Vector3(0, accel.getY() * steps[j], 0); for (int i = 0; i < particleSize; i++) { Vector3 vertex = system.getGeometry().vertices().get(i); vertex.addSelf(velocity); vertex.addSelf(addVelocities[j][i]); vertex.addSelf(wind); vertex.addSelf(addAccel); // do slow // vertex.getPosition().addSelf(winds[i]); } system.getGeometry().setVerticesNeedUpdate(true); ((ParticleBasicMaterial) system.getMaterial()).setSize(baseSize + changeSize * steps[j]); ((ParticleBasicMaterial) system.getMaterial()) .setOpacity(Math.max(0, 1 - changeOpacity * steps[j])); steps[j]++; if (steps[j] == maxStep) { reset(j); steps[j] = 0; } } index++; if (index == maxStep) { index = 0; } }