babylon.solidParticle.ts 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 = new Vector3(1.0, 1.0, 1.0); // 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. /**
  21. * Creates a Solid Particle object.
  22. * Don't create particles manually, use instead the Solid Particle System internal tools like _addParticle()
  23. * `particleIndex` (integer) is the particle index in the Solid Particle System pool. It's also the particle identifier.
  24. * `positionIndex` (integer) is the starting index of the particle vertices in the SPS "positions" array.
  25. * `model` (ModelShape) is a reference to the model shape on what the particle is designed.
  26. * `shapeId` (integer) is the model shape identifier in the SPS.
  27. * `idxInShape` (integer) is the index of the particle in the current model (ex: the 10th box of addShape(box, 30))
  28. * `modelBoundingInfo` is the reference to the model BoundingInfo used for intersection computations.
  29. */
  30. constructor(particleIndex: number, positionIndex: number, model: ModelShape, shapeId: number, idxInShape: number, sps: SolidParticleSystem, modelBoundingInfo?: BoundingInfo) {
  31. this.idx = particleIndex;
  32. this._pos = positionIndex;
  33. this._model = model;
  34. this.shapeId = shapeId;
  35. this.idxInShape = idxInShape;
  36. this._sps = sps;
  37. if (modelBoundingInfo) {
  38. this._modelBoundingInfo = modelBoundingInfo;
  39. this._boundingInfo = new BoundingInfo(modelBoundingInfo.minimum, modelBoundingInfo.maximum);
  40. }
  41. }
  42. /**
  43. * legacy support, changed scale to scaling
  44. */
  45. public get scale(): Vector3 {
  46. return this.scaling;
  47. }
  48. public set scale(scale: Vector3) {
  49. this.scaling = scale;
  50. }
  51. /**
  52. * legacy support, changed quaternion to rotationQuaternion
  53. */
  54. public get quaternion(): Quaternion {
  55. return this.rotationQuaternion;
  56. }
  57. public set quaternion(q: Quaternion) {
  58. this.rotationQuaternion = q;
  59. }
  60. /**
  61. * Returns a boolean. True if the particle intersects another particle or another mesh, else false.
  62. * The intersection is computed on the particle bounding sphere and Axis Aligned Bounding Box (AABB)
  63. * `target` is the object (solid particle or mesh) what the intersection is computed against.
  64. */
  65. public intersectsMesh(target: Mesh | SolidParticle): boolean {
  66. if (!this._boundingInfo || !target._boundingInfo) {
  67. return false;
  68. }
  69. if (this._sps._bSphereOnly) {
  70. return BoundingSphere.Intersects(this._boundingInfo.boundingSphere, target._boundingInfo.boundingSphere);
  71. }
  72. return this._boundingInfo.intersects(target._boundingInfo, false);
  73. }
  74. }
  75. export class ModelShape {
  76. public shapeID: number;
  77. public _shape: Vector3[];
  78. public _shapeUV: number[];
  79. public _positionFunction: (particle: SolidParticle, i: number, s: number) => void;
  80. public _vertexFunction: (particle: SolidParticle, vertex: Vector3, i: number) => void;
  81. /**
  82. * 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.
  83. * SPS internal tool, don't use it manually.
  84. */
  85. constructor(id: number, shape: Vector3[], shapeUV: number[], posFunction: (particle: SolidParticle, i: number, s: number) => void, vtxFunction: (particle: SolidParticle, vertex: Vector3, i: number) => void) {
  86. this.shapeID = id;
  87. this._shape = shape;
  88. this._shapeUV = shapeUV;
  89. this._positionFunction = posFunction;
  90. this._vertexFunction = vtxFunction;
  91. }
  92. }
  93. }