Particles.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /**
  2. * @author Mark Kellogg - http://www.github.com/mkkellogg
  3. */
  4. THREE.Particles = THREE.Particles || {};
  5. THREE.Particles.RangeType = Object.freeze( {
  6. Cube: 1,
  7. Sphere: 2,
  8. Plane: 3
  9. } );
  10. THREE.Particles.Constants = Object.freeze( {
  11. VerticesPerParticle: 6,
  12. DegreesToRadians: Math.PI / 180.0
  13. } );
  14. THREE.Particles.Random = THREE.Particles.Random || {};
  15. THREE.Particles.Random.getRandomVectorCube = function( vector, offset, range, edgeClamp ) {
  16. var x = Math.random() - 0.5;
  17. var y = Math.random() - 0.5;
  18. var z = Math.random() - 0.5;
  19. var w = Math.random() - 0.5;
  20. vector.set( x, y, z, w );
  21. if ( edgeClamp ) {
  22. var max = Math.max ( Math.abs( vector.x ), Math.max ( Math.abs( vector.y ), Math.abs( vector.z ) ) );
  23. vector.multiplyScalar( 1.0 / max );
  24. }
  25. vector.multiplyVectors( range, vector );
  26. vector.addVectors( offset, vector );
  27. }
  28. THREE.Particles.Random.getRandomVectorSphere = function( vector, offset, range, edgeClamp ) {
  29. var x = Math.random() - 0.5;
  30. var y = Math.random() - 0.5;
  31. var z = Math.random() - 0.5;
  32. var w = Math.random() - 0.5;
  33. vector.set( x, y, z, w );
  34. vector.normalize();
  35. vector.multiplyVectors( vector, range );
  36. if ( ! edgeClamp ) {
  37. var adjust = Math.random() * 2.0 - 1.0;
  38. vector.multiplyScalar( adjust );
  39. }
  40. vector.addVectors( vector, offset );
  41. }
  42. THREE.Particles.SingularVector = function( x ) {
  43. this.x = x;
  44. }
  45. THREE.Particles.SingularVector.prototype.copy = function( dest ) {
  46. this.x = dest.x;
  47. }
  48. THREE.Particles.SingularVector.prototype.set = function( x ) {
  49. this.x = x;
  50. }
  51. THREE.Particles.SingularVector.prototype.normalize = function() {
  52. //return this;
  53. }
  54. THREE.Particles.SingularVector.prototype.multiplyScalar = function( x ) {
  55. this.x *= x;
  56. }
  57. THREE.Particles.SingularVector.prototype.lerp = function( dest, f ) {
  58. this.x = this.x + f * ( dest.x - this.x );
  59. }
  60. THREE.Particles.SingularVector.prototype.addVectors = function( vector, offset ) {
  61. vector.x += offset;
  62. }
  63. THREE.Particles.SingularVector.prototype.multiplyVectors = function( vector, rangeVector ) {
  64. vector.x *= rangeVector.x;
  65. }