UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

68 lines (53 loc) 1.57 kB
import { ModifyPatchSampler2DAction } from "./ModifyPatchSampler2DAction.js"; export class PatchTerrainHeightAction extends ModifyPatchSampler2DAction { /** * * @param {Terrain} terrain * @param {number} x * @param {number} y * @param {number} width * @param {number} height */ constructor(terrain, x, y, width, height) { super(terrain.samplerHeight, [x, y, x + width, y + height]); /** * * @type {Terrain} */ this.terrain = terrain; } async updateTerrain() { /** * * @type {Terrain} */ const terrain = this.terrain; terrain.updateHeightTexture(); terrain.updateWorkerHeights(); /** * * @type {Sampler2D} */ const heightMap = terrain.samplerHeight; /** * * @type {TerrainTileManager} */ const tiles = terrain.__tiles; const x = this.x; const y = this.y; const u0 = x / heightMap.width; const u1 = (x + this.patch.width) / heightMap.height; const v0 = y / heightMap.height; const v1 = (y + this.patch.height) / heightMap.height; tiles.rebuildTilesByUV(u0, v0, u1, v1); } async apply(context) { await super.apply(context); await this.updateTerrain(); } async revert(context) { await super.revert(context); await this.updateTerrain(); } }