babylon.pickingInfo.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. var BABYLON = BABYLON || {};
  3. (function () {
  4. BABYLON.PickingInfo = function () {
  5. };
  6. // Properties
  7. BABYLON.PickingInfo.prototype.hit = false;
  8. BABYLON.PickingInfo.prototype.distance = 0;
  9. BABYLON.PickingInfo.prototype.pickedPoint = null;
  10. BABYLON.PickingInfo.prototype.pickedMesh = null;
  11. BABYLON.PickingInfo.prototype.bu = 0;
  12. BABYLON.PickingInfo.prototype.bv = 0;
  13. BABYLON.PickingInfo.prototype.faceId = -1;
  14. // Methods
  15. BABYLON.PickingInfo.prototype.getNormal = function() {
  16. if (!this.pickedMesh) {
  17. return null;
  18. }
  19. var indices = this.pickedMesh.getIndices();
  20. var normals = this.pickedMesh.getVerticesData(BABYLON.VertexBuffer.NormalKind);
  21. var normal0 = BABYLON.Vector3.FromArray(normals , indices[this.faceId]);
  22. var normal1 = BABYLON.Vector3.FromArray(normals, indices[this.faceId + 1]);
  23. var normal2 = BABYLON.Vector3.FromArray(normals, indices[this.faceId + 2]);
  24. normal0 = normal0.scale(this.bu);
  25. normal1 = normal1.scale(this.bv);
  26. normal2 = normal2.scale(1.0 - this.bu - this.bv);
  27. return new BABYLON.Vector3(normal0.x + normal1.x + normal2.x, normal0.y + normal1.y + normal2.y, normal0.z + normal1.z + normal2.z);
  28. };
  29. })();