babylon.pickingInfo.js 2.9 KB

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