babylon.groundMesh.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. module BABYLON {
  2. export class GroundMesh extends Mesh {
  3. public generateOctree = false;
  4. private _worldInverse = new 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, octreeBlocksSize = 32): void {
  13. this._subdivisions = chunksCount;
  14. this.subdivide(this._subdivisions);
  15. this.createOrUpdateSubmeshesOctree(octreeBlocksSize);
  16. }
  17. public getHeightAtCoordinates(x: number, z: number): number {
  18. var ray = new Ray(new Vector3(x, this.getBoundingInfo().boundingBox.maximumWorld.y + 1, z), new Vector3(0, -1, 0));
  19. this.getWorldMatrix().invertToRef(this._worldInverse);
  20. ray = Ray.Transform(ray, this._worldInverse);
  21. var pickInfo = this.intersects(ray);
  22. if (pickInfo.hit) {
  23. return pickInfo.pickedPoint.y;
  24. }
  25. return 0;
  26. }
  27. }
  28. }