three.js particle system


SUBMITTED BY: Guest

DATE: Aug. 28, 2012, 7:48 a.m.

FORMAT: JavaScript

SIZE: 1.3 kB

HITS: 1740

  1. /**
  2. *
  3. * Class Name : Particle
  4. * Created : 28/08/2012
  5. * Require : Three.js
  6. *
  7. **/
  8. GAME_ENGINE.Particle = function(picture, psize, max) {
  9. this.psize = (psize) ? psize : 20;
  10. this.maxParticleCount = (max) ? max : 100;
  11. this.emitting = false;
  12. this.particlesCount = 0;
  13. this.particles = new THREE.Geometry(),
  14. this.pMaterial = new THREE.ParticleBasicMaterial({ color: 0xFFFFFF, size: psize, map: THREE.ImageUtils.loadTexture(picture), blending: THREE.AdditiveBlending, transparent: true });
  15. this.particleSystem = new THREE.ParticleSystem(this.particles, this.pMaterial);
  16. this.particleSystem.sortParticles = true;
  17. this.position = new THREE.Vector3(0, 0, 0);
  18. }
  19. GAME_ENGINE.Particle.prototype.getEmitter = function() {
  20. return this.particleSystem;
  21. };
  22. GAME_ENGINE.Particle.prototype.start = function() {
  23. this.emitting = true;
  24. };
  25. GAME_ENGINE.Particle.prototype.stop = function() {
  26. this.emitting = false;
  27. };
  28. GAME_ENGINE.Particle.prototype.update = function( delta ) {
  29. if (this.emitting) {
  30. while(this.particlesCount < this.maxParticleCount) {
  31. particle = new THREE.Vertex(this.position );
  32. this.particles.vertices.push(particle);
  33. this.particlesCount +=1;
  34. }
  35. }
  36. };

comments powered by Disqus