babylon.groundMesh.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. var __extends = this.__extends || function (d, b) {
  2. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  3. function __() { this.constructor = d; }
  4. __.prototype = b.prototype;
  5. d.prototype = new __();
  6. };
  7. var BABYLON;
  8. (function (BABYLON) {
  9. var GroundMesh = (function (_super) {
  10. __extends(GroundMesh, _super);
  11. function GroundMesh(name, scene) {
  12. _super.call(this, name, scene);
  13. this.chunkSize = 128;
  14. this._worldInverse = new BABYLON.Matrix();
  15. }
  16. Object.defineProperty(GroundMesh.prototype, "subdivisions", {
  17. get: function () {
  18. return this._subdivisions;
  19. },
  20. enumerable: true,
  21. configurable: true
  22. });
  23. GroundMesh.prototype.optimize = function (subdivisions) {
  24. if (this.getTotalVertices() < 2000) {
  25. BABYLON.Tools.Warn("Optimizing GroundMesh requires at least 2000 vertices.");
  26. }
  27. this.subdivide(subdivisions || this._subdivisions);
  28. this.createOrUpdateSubmeshesOctree();
  29. };
  30. GroundMesh.prototype.getHeightAtCoordinates = function (x, z) {
  31. var ray = new BABYLON.Ray(new BABYLON.Vector3(x, this.getBoundingInfo().boundingBox.maximumWorld.y + 1, z), new BABYLON.Vector3(0, -1, 0));
  32. this.getWorldMatrix().invertToRef(this._worldInverse);
  33. ray = BABYLON.Ray.Transform(ray, this._worldInverse);
  34. var pickInfo = this.intersects(ray);
  35. if (pickInfo.hit) {
  36. var result = BABYLON.Vector3.TransformCoordinates(pickInfo.pickedPoint, this.getWorldMatrix());
  37. return result.y;
  38. }
  39. return 0;
  40. };
  41. return GroundMesh;
  42. })(BABYLON.Mesh);
  43. BABYLON.GroundMesh = GroundMesh;
  44. })(BABYLON || (BABYLON = {}));
  45. //# sourceMappingURL=babylon.groundMesh.js.map