babylon.groundMesh.ts 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. module BABYLON {
  2. export class GroundMesh extends Mesh {
  3. public generateOctree = false;
  4. private _worldInverse = new BABYLON.Matrix();
  5. public _subdivisions: number;
  6. constructor(name: string, scene: Scene) {
  7. super(name, scene);
  8. }
  9. public get subdivisions(): number {
  10. return this._subdivisions;
  11. }
  12. public optimize(chunksCount: number): void {
  13. this.subdivide(this._subdivisions);
  14. this.createOrUpdateSubmeshesOctree(32);
  15. }
  16. public getHeightAtCoordinates(x: number, z: number): number {
  17. var ray = new Ray(new Vector3(x, this.getBoundingInfo().boundingBox.maximumWorld.y + 1, z), new BABYLON.Vector3(0, -1, 0));
  18. this.getWorldMatrix().invertToRef(this._worldInverse);
  19. ray = Ray.Transform(ray, this._worldInverse);
  20. var pickInfo = this.intersects(ray);
  21. if (pickInfo.hit) {
  22. return pickInfo.pickedPoint.y;
  23. }
  24. return 0;
  25. }
  26. }
  27. }