"use strict";var Heightmap=function(t,e,r){this.name=e,this.map=t,this.valueMap=null,this.heightmapProperties=r,this._tmp_pixelColor=null};Heightmap.createFromWorld=function(t,e,r){var i=new Heightmap(t,e,r);return i.valueMap=new Uint8Array(i.map.width*i.map.height*4),i},Heightmap.createFromImage=function(t,e,r,i,o){var a=new Heightmap(e,r,i),h=assetLoader.loadImageRawData(t,a,"valueMap");return o.waitFor(h),h.startJob(),a},Heightmap.prototype.getWorldHeightAt=function(t,e,r){return this._tmp_pixelColor=Renderer.readPixelColor(this.valueMap,this.map.width,this.map.height,t,e),this.getWorldHeightForColor(this._tmp_pixelColor,r)},Heightmap.prototype.getWorldHeightForColor=function(t,e){var r=renderer.unpackDepth24(t);return this.getWorldHeightForDepth(r)},Heightmap.prototype.getWorldHeightForDepth=function(t){var e=t*this.heightmapProperties.nearToFarDistance,r=this.heightmapProperties.cameraNearPosition-e;return Math.abs(r-this.heightmapProperties.cameraNearPosition)<=.1?this.getWorldHeightForDepth(1):r},Heightmap.prototype.getWorldHeightAtEntity=function(t){return t.computeHeightmapCoordinates(),this.getWorldHeightAt(t.heightmapCoord.x,t.heightmapCoord.y,t)},Heightmap.prototype.getAveragedWorldHeightAtEntity=function(t){return t.computeHeightmapCoordinates(),this.averageFrom9samples(t.heightmapCoord.x,t.heightmapCoord.y,t,this.getWorldHeightAt.bind(this))},Heightmap.prototype.averageFrom9samples=function(t,e,r,i){var o=0;return o+=i(t-1,e+1,r),o+=i(t,e+1,r),o+=i(t+1,e+1,r),o+=i(t-1,e,r),o+=2*i(t,e,r),o+=i(t+1,e,r),o+=i(t-1,e-1,r),o+=i(t,e-1,r),o+=i(t+1,e-1,r),o/=9},Heightmap.isColorBackground=function(t){return t[0]===Preferences.Heightmap.BACKGROUND_COLOR_RGB.x&&t[1]===Preferences.Heightmap.BACKGROUND_COLOR_RGB.y&&t[2]===Preferences.Heightmap.BACKGROUND_COLOR_RGB.z},Heightmap.prototype.isPlayerOnBackgroundColor=function(t){var e=Renderer.readPixelColor(this.valueMap,this.map.width,this.map.height,t.heightmapCoord.x,t.heightmapCoord.y);return Heightmap.isColorBackground(e)};