babylon.solidParticle.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. module BABYLON {
  2. export class SolidParticle {
  3. public idx: number = 0; // particle global index
  4. public color = new Color4(1.0, 1.0, 1.0, 1.0); // color
  5. public position = Vector3.Zero(); // position
  6. public rotation = Vector3.Zero(); // rotation
  7. public rotationQuaternion: Quaternion; // quaternion, will overwrite rotation
  8. public scaling = Vector3.One(); // scaling
  9. public uvs = new Vector4(0.0, 0.0, 1.0, 1.0); // uvs
  10. public velocity = Vector3.Zero(); // velocity
  11. public alive = true; // alive
  12. public isVisible = true; // visibility
  13. public _pos: number = 0; // index of this particle in the global "positions" array
  14. public _model: ModelShape; // model shape reference
  15. public shapeId: number = 0; // model shape id
  16. public idxInShape: number = 0; // index of the particle in its shape id
  17. public _modelBoundingInfo: BoundingInfo; // reference to the shape model BoundingInfo object
  18. public _boundingInfo: BoundingInfo; // particle BoundingInfo
  19. public _sps: SolidParticleSystem; // reference to the SPS what the particle belongs to
  20. public _stillInvisible: boolean = false; // still set as invisible in order to skip useless computations
  21. /**
  22. * Creates a Solid Particle object.
  23. * Don't create particles manually, use instead the Solid Particle System internal tools like _addParticle()
  24. * `particleIndex` (integer) is the particle index in the Solid Particle System pool. It's also the particle identifier.
  25. * `positionIndex` (integer) is the starting index of the particle vertices in the SPS "positions" array.
  26. * `model` (ModelShape) is a reference to the model shape on what the particle is designed.
  27. * `shapeId` (integer) is the model shape identifier in the SPS.
  28. * `idxInShape` (integer) is the index of the particle in the current model (ex: the 10th box of addShape(box, 30))
  29. * `modelBoundingInfo` is the reference to the model BoundingInfo used for intersection computations.
  30. */
  31. constructor(particleIndex: number, positionIndex: number, model: ModelShape, shapeId: number, idxInShape: number, sps: SolidParticleSystem, modelBoundingInfo?: BoundingInfo) {
  32. this.idx = particleIndex;
  33. this._pos = positionIndex;
  34. this._model = model;
  35. this.shapeId = shapeId;
  36. this.idxInShape = idxInShape;
  37. this._sps = sps;
  38. if (modelBoundingInfo) {
  39. this._modelBoundingInfo = modelBoundingInfo;
  40. this._boundingInfo = new BoundingInfo(modelBoundingInfo.minimum, modelBoundingInfo.maximum);
  41. }
  42. }
  43. /**
  44. * legacy support, changed scale to scaling
  45. */
  46. public get scale(): Vector3 {
  47. return this.scaling;
  48. }
  49. public set scale(scale: Vector3) {
  50. this.scaling = scale;
  51. }
  52. /**
  53. * legacy support, changed quaternion to rotationQuaternion
  54. */
  55. public get quaternion(): Quaternion {
  56. return this.rotationQuaternion;
  57. }
  58. public set quaternion(q: Quaternion) {
  59. this.rotationQuaternion = q;
  60. }
  61. /**
  62. * Returns a boolean. True if the particle intersects another particle or another mesh, else false.
  63. * The intersection is computed on the particle bounding sphere and Axis Aligned Bounding Box (AABB)
  64. * `target` is the object (solid particle or mesh) what the intersection is computed against.
  65. */
  66. public intersectsMesh(target: Mesh | SolidParticle): boolean {
  67. if (!this._boundingInfo || !target._boundingInfo) {
  68. return false;
  69. }
  70. if (this._sps._bSphereOnly) {
  71. return BoundingSphere.Intersects(this._boundingInfo.boundingSphere, target._boundingInfo.boundingSphere);
  72. }
  73. return this._boundingInfo.intersects(target._boundingInfo, false);
  74. }
  75. }
  76. export class ModelShape {
  77. public shapeID: number;
  78. public _shape: Vector3[];
  79. public _shapeUV: number[];
  80. public _positionFunction: (particle: SolidParticle, i: number, s: number) => void;
  81. public _vertexFunction: (particle: SolidParticle, vertex: Vector3, i: number) => void;
  82. /**
  83. * Creates a ModelShape object. This is an internal simplified reference to a mesh used as for a model to replicate particles from by the SPS.
  84. * SPS internal tool, don't use it manually.
  85. */
  86. constructor(id: number, shape: Vector3[], shapeUV: number[], posFunction: (particle: SolidParticle, i: number, s: number) => void, vtxFunction: (particle: SolidParticle, vertex: Vector3, i: number) => void) {
  87. this.shapeID = id;
  88. this._shape = shape;
  89. this._shapeUV = shapeUV;
  90. this._positionFunction = posFunction;
  91. this._vertexFunction = vtxFunction;
  92. }
  93. }
  94. }