|
532 | 532 | var colorIndex = 0; |
533 | 533 | var uvidx = 0; |
534 | 534 | var uvIndex = 0; |
| 535 | + var pt = 0; |
535 | 536 |
|
536 | 537 | if (this._computeBoundingBox) { |
537 | 538 | Vector3.FromFloatsToRef(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE, this._minimum); |
|
547 | 548 |
|
548 | 549 | // call to custom user function to update the particle properties |
549 | 550 | this.updateParticle(this._particle); |
| 551 | + |
| 552 | + if (this._particle.isVisible) { |
550 | 553 |
|
551 | | - // particle rotation matrix |
552 | | - if (this.billboard) { |
553 | | - this._particle.rotation.x = 0.0; |
554 | | - this._particle.rotation.y = 0.0; |
555 | | - } |
556 | | - if (this._computeParticleRotation) { |
557 | | - if (this._particle.rotationQuaternion) { |
558 | | - this._quaternion.copyFrom(this._particle.rotationQuaternion); |
559 | | - } else { |
560 | | - this._yaw = this._particle.rotation.y; |
561 | | - this._pitch = this._particle.rotation.x; |
562 | | - this._roll = this._particle.rotation.z; |
563 | | - this._quaternionRotationYPR(); |
| 554 | + // particle rotation matrix |
| 555 | + if (this.billboard) { |
| 556 | + this._particle.rotation.x = 0.0; |
| 557 | + this._particle.rotation.y = 0.0; |
564 | 558 | } |
565 | | - this._quaternionToRotationMatrix(); |
566 | | - } |
567 | | - |
568 | | - for (var pt = 0; pt < this._shape.length; pt++) { |
569 | | - idx = index + pt * 3; |
570 | | - colidx = colorIndex + pt * 4; |
571 | | - uvidx = uvIndex + pt * 2; |
572 | | - |
573 | | - this._vertex.x = this._shape[pt].x; |
574 | | - this._vertex.y = this._shape[pt].y; |
575 | | - this._vertex.z = this._shape[pt].z; |
576 | | - |
577 | | - if (this._computeParticleVertex) { |
578 | | - this.updateParticleVertex(this._particle, this._vertex, pt); |
| 559 | + if (this._computeParticleRotation) { |
| 560 | + if (this._particle.rotationQuaternion) { |
| 561 | + this._quaternion.copyFrom(this._particle.rotationQuaternion); |
| 562 | + } else { |
| 563 | + this._yaw = this._particle.rotation.y; |
| 564 | + this._pitch = this._particle.rotation.x; |
| 565 | + this._roll = this._particle.rotation.z; |
| 566 | + this._quaternionRotationYPR(); |
| 567 | + } |
| 568 | + this._quaternionToRotationMatrix(); |
579 | 569 | } |
580 | 570 |
|
581 | | - // positions |
582 | | - this._vertex.x *= this._particle.scaling.x; |
583 | | - this._vertex.y *= this._particle.scaling.y; |
584 | | - this._vertex.z *= this._particle.scaling.z; |
585 | | - |
586 | | - this._w = (this._vertex.x * this._rotMatrix.m[3]) + (this._vertex.y * this._rotMatrix.m[7]) + (this._vertex.z * this._rotMatrix.m[11]) + this._rotMatrix.m[15]; |
587 | | - this._rotated.x = ((this._vertex.x * this._rotMatrix.m[0]) + (this._vertex.y * this._rotMatrix.m[4]) + (this._vertex.z * this._rotMatrix.m[8]) + this._rotMatrix.m[12]) / this._w; |
588 | | - this._rotated.y = ((this._vertex.x * this._rotMatrix.m[1]) + (this._vertex.y * this._rotMatrix.m[5]) + (this._vertex.z * this._rotMatrix.m[9]) + this._rotMatrix.m[13]) / this._w; |
589 | | - this._rotated.z = ((this._vertex.x * this._rotMatrix.m[2]) + (this._vertex.y * this._rotMatrix.m[6]) + (this._vertex.z * this._rotMatrix.m[10]) + this._rotMatrix.m[14]) / this._w; |
| 571 | + // particle vertex loop |
| 572 | + for (pt = 0; pt < this._shape.length; pt++) { |
| 573 | + idx = index + pt * 3; |
| 574 | + colidx = colorIndex + pt * 4; |
| 575 | + uvidx = uvIndex + pt * 2; |
590 | 576 |
|
591 | | - this._positions32[idx] = this._particle.position.x + this._cam_axisX.x * this._rotated.x + this._cam_axisY.x * this._rotated.y + this._cam_axisZ.x * this._rotated.z; |
592 | | - this._positions32[idx + 1] = this._particle.position.y + this._cam_axisX.y * this._rotated.x + this._cam_axisY.y * this._rotated.y + this._cam_axisZ.y * this._rotated.z; |
593 | | - this._positions32[idx + 2] = this._particle.position.z + this._cam_axisX.z * this._rotated.x + this._cam_axisY.z * this._rotated.y + this._cam_axisZ.z * this._rotated.z; |
| 577 | + this._vertex.x = this._shape[pt].x; |
| 578 | + this._vertex.y = this._shape[pt].y; |
| 579 | + this._vertex.z = this._shape[pt].z; |
594 | 580 |
|
595 | | - if (this._computeBoundingBox) { |
596 | | - if (this._positions32[idx] < this._minimum.x) { |
597 | | - this._minimum.x = this._positions32[idx]; |
598 | | - } |
599 | | - if (this._positions32[idx] > this._maximum.x) { |
600 | | - this._maximum.x = this._positions32[idx]; |
601 | | - } |
602 | | - if (this._positions32[idx + 1] < this._minimum.y) { |
603 | | - this._minimum.y = this._positions32[idx + 1]; |
604 | | - } |
605 | | - if (this._positions32[idx + 1] > this._maximum.y) { |
606 | | - this._maximum.y = this._positions32[idx + 1]; |
| 581 | + if (this._computeParticleVertex) { |
| 582 | + this.updateParticleVertex(this._particle, this._vertex, pt); |
607 | 583 | } |
608 | | - if (this._positions32[idx + 2] < this._minimum.z) { |
609 | | - this._minimum.z = this._positions32[idx + 2]; |
610 | | - } |
611 | | - if (this._positions32[idx + 2] > this._maximum.z) { |
612 | | - this._maximum.z = this._positions32[idx + 2]; |
| 584 | + |
| 585 | + // positions |
| 586 | + this._vertex.x *= this._particle.scaling.x; |
| 587 | + this._vertex.y *= this._particle.scaling.y; |
| 588 | + this._vertex.z *= this._particle.scaling.z; |
| 589 | + |
| 590 | + this._w = (this._vertex.x * this._rotMatrix.m[3]) + (this._vertex.y * this._rotMatrix.m[7]) + (this._vertex.z * this._rotMatrix.m[11]) + this._rotMatrix.m[15]; |
| 591 | + this._rotated.x = ((this._vertex.x * this._rotMatrix.m[0]) + (this._vertex.y * this._rotMatrix.m[4]) + (this._vertex.z * this._rotMatrix.m[8]) + this._rotMatrix.m[12]) / this._w; |
| 592 | + this._rotated.y = ((this._vertex.x * this._rotMatrix.m[1]) + (this._vertex.y * this._rotMatrix.m[5]) + (this._vertex.z * this._rotMatrix.m[9]) + this._rotMatrix.m[13]) / this._w; |
| 593 | + this._rotated.z = ((this._vertex.x * this._rotMatrix.m[2]) + (this._vertex.y * this._rotMatrix.m[6]) + (this._vertex.z * this._rotMatrix.m[10]) + this._rotMatrix.m[14]) / this._w; |
| 594 | + |
| 595 | + this._positions32[idx] = this._particle.position.x + this._cam_axisX.x * this._rotated.x + this._cam_axisY.x * this._rotated.y + this._cam_axisZ.x * this._rotated.z; |
| 596 | + this._positions32[idx + 1] = this._particle.position.y + this._cam_axisX.y * this._rotated.x + this._cam_axisY.y * this._rotated.y + this._cam_axisZ.y * this._rotated.z; |
| 597 | + this._positions32[idx + 2] = this._particle.position.z + this._cam_axisX.z * this._rotated.x + this._cam_axisY.z * this._rotated.y + this._cam_axisZ.z * this._rotated.z; |
| 598 | + |
| 599 | + if (this._computeBoundingBox) { |
| 600 | + if (this._positions32[idx] < this._minimum.x) { |
| 601 | + this._minimum.x = this._positions32[idx]; |
| 602 | + } |
| 603 | + if (this._positions32[idx] > this._maximum.x) { |
| 604 | + this._maximum.x = this._positions32[idx]; |
| 605 | + } |
| 606 | + if (this._positions32[idx + 1] < this._minimum.y) { |
| 607 | + this._minimum.y = this._positions32[idx + 1]; |
| 608 | + } |
| 609 | + if (this._positions32[idx + 1] > this._maximum.y) { |
| 610 | + this._maximum.y = this._positions32[idx + 1]; |
| 611 | + } |
| 612 | + if (this._positions32[idx + 2] < this._minimum.z) { |
| 613 | + this._minimum.z = this._positions32[idx + 2]; |
| 614 | + } |
| 615 | + if (this._positions32[idx + 2] > this._maximum.z) { |
| 616 | + this._maximum.z = this._positions32[idx + 2]; |
| 617 | + } |
613 | 618 | } |
614 | | - } |
615 | 619 |
|
616 | | - // normals : if the particles can't be morphed then just rotate the normals |
617 | | - if (!this._computeParticleVertex && !this.billboard) { |
618 | | - this._normal.x = this._fixedNormal32[idx]; |
619 | | - this._normal.y = this._fixedNormal32[idx + 1]; |
620 | | - this._normal.z = this._fixedNormal32[idx + 2]; |
| 620 | + // normals : if the particles can't be morphed then just rotate the normals, what if much more faster than ComputeNormals() |
| 621 | + if (!this._computeParticleVertex && !this.billboard) { |
| 622 | + this._normal.x = this._fixedNormal32[idx]; |
| 623 | + this._normal.y = this._fixedNormal32[idx + 1]; |
| 624 | + this._normal.z = this._fixedNormal32[idx + 2]; |
621 | 625 |
|
622 | | - this._w = (this._normal.x * this._rotMatrix.m[3]) + (this._normal.y * this._rotMatrix.m[7]) + (this._normal.z * this._rotMatrix.m[11]) + this._rotMatrix.m[15]; |
623 | | - this._rotated.x = ((this._normal.x * this._rotMatrix.m[0]) + (this._normal.y * this._rotMatrix.m[4]) + (this._normal.z * this._rotMatrix.m[8]) + this._rotMatrix.m[12]) / this._w; |
624 | | - this._rotated.y = ((this._normal.x * this._rotMatrix.m[1]) + (this._normal.y * this._rotMatrix.m[5]) + (this._normal.z * this._rotMatrix.m[9]) + this._rotMatrix.m[13]) / this._w; |
625 | | - this._rotated.z = ((this._normal.x * this._rotMatrix.m[2]) + (this._normal.y * this._rotMatrix.m[6]) + (this._normal.z * this._rotMatrix.m[10]) + this._rotMatrix.m[14]) / this._w; |
| 626 | + this._w = (this._normal.x * this._rotMatrix.m[3]) + (this._normal.y * this._rotMatrix.m[7]) + (this._normal.z * this._rotMatrix.m[11]) + this._rotMatrix.m[15]; |
| 627 | + this._rotated.x = ((this._normal.x * this._rotMatrix.m[0]) + (this._normal.y * this._rotMatrix.m[4]) + (this._normal.z * this._rotMatrix.m[8]) + this._rotMatrix.m[12]) / this._w; |
| 628 | + this._rotated.y = ((this._normal.x * this._rotMatrix.m[1]) + (this._normal.y * this._rotMatrix.m[5]) + (this._normal.z * this._rotMatrix.m[9]) + this._rotMatrix.m[13]) / this._w; |
| 629 | + this._rotated.z = ((this._normal.x * this._rotMatrix.m[2]) + (this._normal.y * this._rotMatrix.m[6]) + (this._normal.z * this._rotMatrix.m[10]) + this._rotMatrix.m[14]) / this._w; |
626 | 630 |
|
627 | | - this._normals32[idx] = this._cam_axisX.x * this._rotated.x + this._cam_axisY.x * this._rotated.y + this._cam_axisZ.x * this._rotated.z; |
628 | | - this._normals32[idx + 1] = this._cam_axisX.y * this._rotated.x + this._cam_axisY.y * this._rotated.y + this._cam_axisZ.y * this._rotated.z; |
629 | | - this._normals32[idx + 2] = this._cam_axisX.z * this._rotated.x + this._cam_axisY.z * this._rotated.y + this._cam_axisZ.z * this._rotated.z; |
630 | | - } |
| 631 | + this._normals32[idx] = this._cam_axisX.x * this._rotated.x + this._cam_axisY.x * this._rotated.y + this._cam_axisZ.x * this._rotated.z; |
| 632 | + this._normals32[idx + 1] = this._cam_axisX.y * this._rotated.x + this._cam_axisY.y * this._rotated.y + this._cam_axisZ.y * this._rotated.z; |
| 633 | + this._normals32[idx + 2] = this._cam_axisX.z * this._rotated.x + this._cam_axisY.z * this._rotated.y + this._cam_axisZ.z * this._rotated.z; |
| 634 | + } |
631 | 635 |
|
632 | | - if (this._computeParticleColor) { |
633 | | - this._colors32[colidx] = this._particle.color.r; |
634 | | - this._colors32[colidx + 1] = this._particle.color.g; |
635 | | - this._colors32[colidx + 2] = this._particle.color.b; |
636 | | - this._colors32[colidx + 3] = this._particle.color.a; |
| 636 | + if (this._computeParticleColor) { |
| 637 | + this._colors32[colidx] = this._particle.color.r; |
| 638 | + this._colors32[colidx + 1] = this._particle.color.g; |
| 639 | + this._colors32[colidx + 2] = this._particle.color.b; |
| 640 | + this._colors32[colidx + 3] = this._particle.color.a; |
| 641 | + } |
| 642 | + |
| 643 | + if (this._computeParticleTexture) { |
| 644 | + this._uvs32[uvidx] = this._shapeUV[pt * 2] * (this._particle.uvs.z - this._particle.uvs.x) + this._particle.uvs.x; |
| 645 | + this._uvs32[uvidx + 1] = this._shapeUV[pt * 2 + 1] * (this._particle.uvs.w - this._particle.uvs.y) + this._particle.uvs.y; |
| 646 | + } |
637 | 647 | } |
638 | 648 |
|
639 | | - if (this._computeParticleTexture) { |
640 | | - this._uvs32[uvidx] = this._shapeUV[pt * 2] * (this._particle.uvs.z - this._particle.uvs.x) + this._particle.uvs.x; |
641 | | - this._uvs32[uvidx + 1] = this._shapeUV[pt * 2 + 1] * (this._particle.uvs.w - this._particle.uvs.y) + this._particle.uvs.y; |
| 649 | + } |
| 650 | + // particle not visible : scaled to zero and positioned to the camera position |
| 651 | + else { |
| 652 | + for (pt = 0; pt < this._shape.length; pt++) { |
| 653 | + idx = index + pt * 3; |
| 654 | + colidx = colorIndex + pt * 4; |
| 655 | + uvidx = uvIndex + pt * 2; |
| 656 | + this._positions32[idx] = this._camera.position.x; |
| 657 | + this._positions32[idx + 1] = this._camera.position.y; |
| 658 | + this._positions32[idx + 2] = this._camera.position.z; |
| 659 | + this._normals32[idx] = 0.0; |
| 660 | + this._normals32[idx + 1] = 0.0; |
| 661 | + this._normals32[idx + 2] = 0.0; |
| 662 | + if (this._computeParticleColor) { |
| 663 | + this._colors32[colidx] = this._particle.color.r; |
| 664 | + this._colors32[colidx + 1] = this._particle.color.g; |
| 665 | + this._colors32[colidx + 2] = this._particle.color.b; |
| 666 | + this._colors32[colidx + 3] = this._particle.color.a; |
| 667 | + } |
| 668 | + if (this._computeParticleTexture) { |
| 669 | + this._uvs32[uvidx] = this._shapeUV[pt * 2] * (this._particle.uvs.z - this._particle.uvs.x) + this._particle.uvs.x; |
| 670 | + this._uvs32[uvidx + 1] = this._shapeUV[pt * 2 + 1] * (this._particle.uvs.w - this._particle.uvs.y) + this._particle.uvs.y; |
| 671 | + } |
642 | 672 | } |
643 | 673 | } |
| 674 | + |
| 675 | + // increment indexes for the next particle |
644 | 676 | index = idx + 3; |
645 | 677 | colorIndex = colidx + 4; |
646 | 678 | uvIndex = uvidx + 2; |
647 | 679 | } |
648 | 680 |
|
| 681 | + // if the VBO must be updated |
649 | 682 | if (update) { |
650 | 683 | if (this._computeParticleColor) { |
651 | 684 | this.mesh.updateVerticesData(VertexBuffer.ColorKind, this._colors32, false, false); |
|
656 | 689 | this.mesh.updateVerticesData(VertexBuffer.PositionKind, this._positions32, false, false); |
657 | 690 | if (!this.mesh.areNormalsFrozen) { |
658 | 691 | if (this._computeParticleVertex || this.billboard) { |
659 | | - // recompute the normals only if the particles can be morphed, update then the normal reference array |
| 692 | + // recompute the normals only if the particles can be morphed, update then also the normal reference array _fixedNormal32[] |
660 | 693 | VertexData.ComputeNormals(this._positions32, this._indices, this._normals32); |
661 | 694 | for (var i = 0; i < this._normals32.length; i++) { |
662 | 695 | this._fixedNormal32[i] = this._normals32[i]; |
|
0 commit comments