babylon.groundMesh.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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 BABYLON.Ray(new BABYLON.Vector3(x, this.getBoundingInfo().boundingBox.maximumWorld.y + 1, z), new BABYLON.Vector3(0, -1, 0));
  18. this.getWorldMatrix().invertToRef(this._worldInverse);
  19. ray = BABYLON.Ray.Transform(ray, this._worldInverse);
  20. var pickInfo = this.intersects(ray);
  21. if (pickInfo.hit) {
  22. var result = BABYLON.Vector3.TransformCoordinates(pickInfo.pickedPoint, this.getWorldMatrix());
  23. return result.y;
  24. }
  25. return 0;
  26. }
  27. }
  28. }