@vrspace/babylonjs
Version:
vrspace.org babylonjs client
120 lines (119 loc) • 4.02 kB
TypeScript
/**
Wrapper around babylonjs dynamic terrain.
See https://github.com/BabylonJS/Extensions/blob/b16eb03254c90438e8f6ea0ff5b3406f52035cd0/DynamicTerrain/src/babylon.dynamicTerrain.ts
*/
export class Terrain extends WorldListener {
constructor(world: any, params?: {
xSize: number;
zSize: number;
visibility: number;
material: any;
});
world: any;
xSize: number;
zSize: number;
visibility: number;
terrainMaterial: any;
checkCollisions: boolean;
enabled: boolean;
sps: any;
sharedTerrain: VRObject;
buildGrid(): void;
mapData: Float32Array<ArrayBuffer>;
params: {
mapSubX: number;
mapSubZ: number;
mapData: Float32Array<ArrayBuffer>;
terrainSub: number;
};
/** Height function used in constructor, intended to be overridden by subclasses
@param x coordinate of current grid element
@param y coordinate of current grid element
@param index index of of current element in mapData array
@param col current column
@param row current row
@returns 0
*/
gridHeight(x: any, z: any, index: any, col: any, row: any): number;
mesh(): any;
init(scene: any): void;
scene: any;
terrain: any;
setEnabled(flag: any): void;
/** Returns true if both this terrain and terrain mesh exist, i.e. safe to use */
isCreated(): any;
/**
Build Solid Particle System, e.g. trees and other objects seeded over the terrain.
Called during initialization, before the terrain is created.
This implementation does nothing.
*/
buildSPS(): void;
/**
Returns index in mapData containing point closest to given x,y.
Mapdata then contains x of the point on returned index, y at index+1 and z at index+2.
*/
findIndex(x: any, z: any): number;
/**
Update a grid element at index to given coordinates.
*/
update(index: any, x: any, y: any, z: any): void;
/**
Set height at given coordinates
@param x coordinate
@param y coordinate
@param height new height
@param refresh default true, triggers terrain update and renders the change
*/
setHeight(x: any, z: any, height: any, refresh?: boolean): number;
/**
Set height at given coordinates
@param x coordinate
@param y coordinate
@param height how much to raise
@param refresh default true, triggers terrain update and renders the change
*/
raise(x: any, z: any, height: any, refresh?: boolean): number;
/**
Set height at given coordinates
@param x coordinate
@param y coordinate
@param depth how deep to dig
@param refresh default true, triggers terrain update and renders the change
*/
dig(x: any, z: any, depth: any, refresh?: boolean): number;
/**
Refresh (compute normals, update and render) the terrain.
Normally terrain only updates when moving around, update needs to be forced after grid data (e.g. height) changes.
@param force default true
*/
refresh(force?: boolean): void;
point(index: any): {
x: any;
y: any;
z: any;
};
/**
* Set internal VRObject that tracks the shared state. Called from added().
* @param {VRObject} obj permament VRObject from Wellcome message
*/
setSharedTerrain(obj: VRObject): void;
/**
* Set terrain texture
* @param {string} imgUrl
*/
setTexture(imgUrl: string): void;
terrainTexture: any;
/**
* WorldListener method, called when an object is added to the scene.
* If added object is instance of Terrain, calls setSharedObject().
* @param {VRObject} added
*/
added(added: VRObject): void;
/**
* Callback that receives network event, set up in setSharedTerrain
* @param {Object} e object containing changes to the VRObject
*/
terrainChanged(e: any): void;
}
import { WorldListener } from '../world/world-listener.js';
import { VRObject } from '../client/vrspace.js';