babylon.pickingInfo.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. var BABYLON;
  2. (function (BABYLON) {
  3. var IntersectionInfo = (function () {
  4. function IntersectionInfo(bu, bv, distance) {
  5. this.bu = bu;
  6. this.bv = bv;
  7. this.distance = distance;
  8. this.faceId = 0;
  9. }
  10. return IntersectionInfo;
  11. })();
  12. BABYLON.IntersectionInfo = IntersectionInfo;
  13. var PickingInfo = (function () {
  14. function PickingInfo() {
  15. this.hit = false;
  16. this.distance = 0;
  17. this.pickedPoint = null;
  18. this.pickedMesh = null;
  19. this.bu = 0;
  20. this.bv = 0;
  21. this.faceId = -1;
  22. }
  23. // Methods
  24. PickingInfo.prototype.getNormal = function () {
  25. if (!this.pickedMesh || !this.pickedMesh.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
  26. return null;
  27. }
  28. var indices = this.pickedMesh.getIndices();
  29. var normals = this.pickedMesh.getVerticesData(BABYLON.VertexBuffer.NormalKind);
  30. var normal0 = BABYLON.Vector3.FromArray(normals, indices[this.faceId * 3] * 3);
  31. var normal1 = BABYLON.Vector3.FromArray(normals, indices[this.faceId * 3 + 1] * 3);
  32. var normal2 = BABYLON.Vector3.FromArray(normals, indices[this.faceId * 3 + 2] * 3);
  33. normal0 = normal0.scale(this.bu);
  34. normal1 = normal1.scale(this.bv);
  35. normal2 = normal2.scale(1.0 - this.bu - this.bv);
  36. return new BABYLON.Vector3(normal0.x + normal1.x + normal2.x, normal0.y + normal1.y + normal2.y, normal0.z + normal1.z + normal2.z);
  37. };
  38. PickingInfo.prototype.getTextureCoordinates = function () {
  39. if (!this.pickedMesh || !this.pickedMesh.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind)) {
  40. return null;
  41. }
  42. var indices = this.pickedMesh.getIndices();
  43. var uvs = this.pickedMesh.getVerticesData(BABYLON.VertexBuffer.UVKind);
  44. var uv0 = BABYLON.Vector2.FromArray(uvs, indices[this.faceId * 3] * 2);
  45. var uv1 = BABYLON.Vector2.FromArray(uvs, indices[this.faceId * 3 + 1] * 2);
  46. var uv2 = BABYLON.Vector2.FromArray(uvs, indices[this.faceId * 3 + 2] * 2);
  47. uv0 = uv0.scale(this.bu);
  48. uv1 = uv1.scale(this.bv);
  49. uv2 = uv2.scale(1.0 - this.bu - this.bv);
  50. return new BABYLON.Vector2(uv0.x + uv1.x + uv2.x, uv0.y + uv1.y + uv2.y);
  51. };
  52. return PickingInfo;
  53. })();
  54. BABYLON.PickingInfo = PickingInfo;
  55. })(BABYLON || (BABYLON = {}));
  56. //# sourceMappingURL=babylon.pickingInfo.js.map