babylon.pickingInfo.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 () {
  27. if (!this.pickedMesh || !this.pickedMesh.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
  28. return null;
  29. }
  30. var indices = this.pickedMesh.getIndices();
  31. var normals = this.pickedMesh.getVerticesData(BABYLON.VertexBuffer.NormalKind);
  32. var normal0 = BABYLON.Vector3.FromArray(normals, indices[this.faceId * 3] * 3);
  33. var normal1 = BABYLON.Vector3.FromArray(normals, indices[this.faceId * 3 + 1] * 3);
  34. var normal2 = BABYLON.Vector3.FromArray(normals, indices[this.faceId * 3 + 2] * 3);
  35. normal0 = normal0.scale(this.bu);
  36. normal1 = normal1.scale(this.bv);
  37. normal2 = normal2.scale(1.0 - this.bu - this.bv);
  38. return new BABYLON.Vector3(normal0.x + normal1.x + normal2.x, normal0.y + normal1.y + normal2.y, normal0.z + normal1.z + normal2.z);
  39. };
  40. PickingInfo.prototype.getTextureCoordinates = function () {
  41. if (!this.pickedMesh || !this.pickedMesh.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind)) {
  42. return null;
  43. }
  44. var indices = this.pickedMesh.getIndices();
  45. var uvs = this.pickedMesh.getVerticesData(BABYLON.VertexBuffer.UVKind);
  46. var uv0 = BABYLON.Vector2.FromArray(uvs, indices[this.faceId * 3] * 2);
  47. var uv1 = BABYLON.Vector2.FromArray(uvs, indices[this.faceId * 3 + 1] * 2);
  48. var uv2 = BABYLON.Vector2.FromArray(uvs, indices[this.faceId * 3 + 2] * 2);
  49. uv0 = uv0.scale(this.bu);
  50. uv1 = uv1.scale(this.bv);
  51. uv2 = uv2.scale(1.0 - this.bu - this.bv);
  52. return new BABYLON.Vector2(uv0.x + uv1.x + uv2.x, uv0.y + uv1.y + uv2.y);
  53. };
  54. return PickingInfo;
  55. })();
  56. BABYLON.PickingInfo = PickingInfo;
  57. })(BABYLON || (BABYLON = {}));
  58. //# sourceMappingURL=babylon.pickingInfo.js.map