babylon.pickingInfo.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. module BABYLON {
  2. export class IntersectionInfo {
  3. public faceId = 0;
  4. constructor(public bu: number, public bv: number, public distance: number) {
  5. }
  6. }
  7. export class PickingInfo {
  8. public hit = false;
  9. public distance = 0;
  10. public pickedPoint = null;
  11. public pickedMesh = null;
  12. public bu = 0;
  13. public bv = 0;
  14. public faceId = -1;
  15. // Methods
  16. public getNormal(): Vector3 {
  17. if (!this.pickedMesh) {
  18. return null;
  19. }
  20. var indices = this.pickedMesh.getIndices();
  21. var normals = this.pickedMesh.getVerticesData(BABYLON.VertexBuffer.NormalKind);
  22. var normal0 = BABYLON.Vector3.FromArray(normals, indices[this.faceId * 3] * 3);
  23. var normal1 = BABYLON.Vector3.FromArray(normals, indices[this.faceId * 3 + 1] * 3);
  24. var normal2 = BABYLON.Vector3.FromArray(normals, indices[this.faceId * 3 + 2] * 3);
  25. normal0 = normal0.scale(this.bu);
  26. normal1 = normal1.scale(this.bv);
  27. normal2 = normal2.scale(1.0 - this.bu - this.bv);
  28. return new BABYLON.Vector3(normal0.x + normal1.x + normal2.x, normal0.y + normal1.y + normal2.y, normal0.z + normal1.z + normal2.z);
  29. }
  30. }
  31. }