From c49f43e5de4908d78ba6fe6c88892a0cf6dbd5ad Mon Sep 17 00:00:00 2001 From: bart <bart.knuiman@wur.nl> Date: Tue, 28 Feb 2023 13:12:15 +0100 Subject: [PATCH] Naming fix depdencies --- Runtime/TerrainBuilder.cs | 42 ++++++++++++++++------------ Runtime/com.wurwander.terrain.asmdef | 4 +-- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/Runtime/TerrainBuilder.cs b/Runtime/TerrainBuilder.cs index 14f2cb4..b31566f 100644 --- a/Runtime/TerrainBuilder.cs +++ b/Runtime/TerrainBuilder.cs @@ -5,6 +5,7 @@ using System.IO; using System.Linq; using System.Threading.Tasks; using Unity.Collections; +using Unity.VisualScripting.YamlDotNet.Core.Events; using UnityEditor; using UnityEngine; using UnityEngine.Networking; @@ -51,16 +52,16 @@ namespace Wander [ReadOnly] public TerrainData terrainData; [ReadOnly] public Terrain terrain; - public Vector2 originWGS84 = new Vector2(51.985365f, 5.664941f); // Copy directly from Google maps. This is Forum on Campus WUR. - public Vector2Int terrainOffset = new Vector2Int(0, 0); - public int controlResolution = 8192; - public int heightMapResolution = 1024; - public bool loadHeight = true; - public float terrainHeight = 300; - public int zoom = 11; - public int numDLRetries = 5; - public bool runOnStart = false; - public Material terrainMat = null; + public Vector2 originWGS84 = new Vector2(51.985365f, 5.664941f); // Copy directly from Google maps. This is Forum on Campus WUR. + public Vector2Int terrainOffset = new Vector2Int(0, 0); + public int controlResolution = 8192; + public int heightMapResolution = 1024; + public bool loadHeight = true; + public float terrainHeight = 300; + public int zoom = 11; + public int numDLRetries = 5; + public bool runOnStart = false; + public Material terrainMat = null; public List<TerrainLayer2> layers; private List<MapTile> requests; @@ -171,15 +172,14 @@ namespace Wander // Size tileSize = RDUtils.CalcTileSizeRD( zoom ); tilePixelSize = RDUtils.RDDefaultTileRes; - nTilesWide = controlResolution / tilePixelSize; - nTilesHigh = controlResolution / tilePixelSize; + nTilesWide = controlResolution / (tilePixelSize); + nTilesHigh = controlResolution / (tilePixelSize); adjustedSize = new Vector3( (float)(nTilesWide*tileSize), terrainHeight, (float)(nTilesHigh*tileSize) ); // Location RDUtils.GPS2RD( originWGS84.x, originWGS84.y, out double rdX, out double rdY ); tileOrigin = RDUtils.RD2Tile( new Vector2( (float)rdX+adjustedSize.x*terrainOffset.x, (float)rdY+adjustedSize.z*terrainOffset.y ), zoom ); rdOrigin = RDUtils.Tile2RD( tileOrigin, zoom ); - } void CreatePixelToLayerIndex() @@ -288,16 +288,19 @@ namespace Wander { byte layerIndex = 0; uint cachedMask = 0; - int x2 = tile.deltaTileX * tilePixelSize; - int y2 = tile.deltaTileY * tilePixelSize; - // !! No need to lock controlData because every tile writes to its own designated area !! + int tx = tile.deltaTileX * tilePixelSize; + int ty = tile.deltaTileY * tilePixelSize; + int of = ty*controlResolution+tx; + int pixelIdx = 0; + // ! No need to lock controlData because every tile writes to its own designated area exactly, no oversampling or undersampling. ! for (int y = 0;y < height;y++) { if (state== State.None) return; // Cancelling. + for (int x = 0;x < width;x++) { - Color32 col = pixelData[y*width+x]; + Color32 col = pixelData[pixelIdx++]; uint colMask = ((uint)col.g<<16) | ((uint)col.b<<8) | (col.a); // Color is stored as ARGB, so for this Color32 struct becomes g,b,a ... because we want RGB. if (cachedMask!=colMask || layerIndex==255) { @@ -307,8 +310,11 @@ namespace Wander } cachedMask = colMask; } - controlData[(y2 + y) * controlResolution + (x2+x)] = layerIndex; + + controlData[of + x] = layerIndex; } + + of += controlResolution; } } diff --git a/Runtime/com.wurwander.terrain.asmdef b/Runtime/com.wurwander.terrain.asmdef index 1219bf4..c152fa9 100644 --- a/Runtime/com.wurwander.terrain.asmdef +++ b/Runtime/com.wurwander.terrain.asmdef @@ -2,8 +2,8 @@ "name": "Terrain", "rootNamespace": "Wander", "references": [ - "Utils", - "GeoTiff" + "GUID:c2a8fdf421d3fc14dbff9693e60a8787", + "GUID:e44d054dba23a8349a137db68e558dce" ], "includePlatforms": [], "excludePlatforms": [], -- GitLab