Skip to content
Snippets Groups Projects
Commit 47f05c41 authored by Knuiman, Bart's avatar Knuiman, Bart
Browse files

Both methods (DownloadTrees and TreeDBLoader) find equal results.

Fixes issue in DownloadTrees of spawning tree 4 times.
parent c254fb2f
Branches
No related tags found
No related merge requests found
......@@ -44,11 +44,12 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: b0bf25b779ba42e43bba214295ca94ec, type: 3}
m_Name:
m_EditorClassIdentifier:
originRdX: 174239.96066186446
originRdY: 442367.23256885586
originRdX: 155173.30289412767
originRdY: 463132.1564750825
bounds:
m_Center: {x: 113.646576, y: 0, z: 419.33517}
m_Extent: {x: 3010.56, y: 50, z: 3010.56}
m_Center: {x: 256.79773, y: 0, z: 297.4294}
m_Extent: {x: 1290.24, y: 50, z: 1290.24}
limitSize: 2025
connString: C:/Data sets/TreesNL.db
groundLayer:
serializedVersion: 2
......@@ -91,3 +92,4 @@ MonoBehaviour:
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
minPixelsForValidTree: 10
......@@ -44,17 +44,17 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 20a87319123acd841bc49a594a546a87, type: 3}
m_Name:
m_EditorClassIdentifier:
offsX: -579.44574
offsY: -51.71903
originRdX: 113431.61460830583
originRdY: 416602.76929983974
boundsSize: 4300.8
boundsExtent: 0
offsX: -173.28226
offsY: -132.65057
originRdX: 155173.30289412767
originRdY: 463132.1564750825
boundsSize: 2580.48
boundsExtent: 1290.24
zoom: 10
numRings: 2
numRings: 1
smallZoom: 12
wgs84Lat: 51.7366
wgs84Lon: 4.785412
wgs84Lat: 52.15636
wgs84Lon: 5.389736
createImage: 0
createTrees: 1
createCsv: 0
......@@ -67,7 +67,10 @@ MonoBehaviour:
maxDownloads: 8
lodDivider: 4
billboardDistance: 700
limitSize: 1000
limitSize: 0
dbgEnable: 0
dbgTileX: 2190
dbgTileY: 1935
types:
- color:
serializedVersion: 2
......
......@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using Unity.Collections;
......@@ -38,6 +39,7 @@ namespace Wander
public int texRes;
public int type;
public bool isAtEdge;
public bool isAtWrongEdge;
}
[Serializable]
......@@ -383,12 +385,18 @@ namespace Wander
var coord = stack[0];
stack.RemoveAt( 0 );
if (coord.x < 0 || coord.x >= texRes || coord.y < 0 || coord.y >= texRes)
if (coord.x < 0 || coord.x >= texRes)
{
island.isAtEdge = true;
continue;
}
if (coord.y < 0 || coord.y >= texRes)
{
island.isAtWrongEdge = true;
break;
}
addr = (coord.y * texRes + coord.x);
if (marked[addr]) // Already evaluated this pixel.
continue;
......@@ -434,7 +442,10 @@ namespace Wander
stack.Add( (coord.x, coord.y+1) );
}
islands.Add( island );
if (!island.isAtWrongEdge)
{
islands.Add( island );
}
// this pixel matched, so we are done, go to next.
break;
......@@ -642,18 +653,30 @@ namespace Wander
stream = new StreamWriter( str );
stream.WriteLine( "rd_x;rd_y;type" );
}
//foreach (var kvp in treeIslandTasks)
//{
// if (!kvp.Value.IsCompletedSuccessfully)
// continue;
// var coord = kvp.Key;
// var islands = kvp.Value.Result;
// CombineOverlaps( islands, coord + new Vector2Int( -1, 0 ), Edge.Left, Edge.Right, prototypeMap, treeInstances, pendingLines );
// CombineOverlaps( islands, coord + new Vector2Int( 1, 0 ), Edge.Right, Edge.Left, prototypeMap, treeInstances, pendingLines );
// CombineOverlaps( islands, coord + new Vector2Int( 0, 1 ), Edge.Bottom, Edge.Top, prototypeMap, treeInstances, pendingLines );
// CombineOverlaps( islands, coord + new Vector2Int( 0, -1 ), Edge.Top, Edge.Bottom, prototypeMap, treeInstances, pendingLines );
//}
foreach (var kvp in treeIslandTasks)
{
if (!kvp.Value.IsCompletedSuccessfully)
continue;
var coord = kvp.Key;
var islands = kvp.Value.Result;
CombineOverlaps( islands, coord + new Vector2Int( -1, 0 ), Edge.Left, Edge.Right, prototypeMap, treeInstances, pendingLines );
CombineOverlaps( islands, coord + new Vector2Int( 1, 0 ), Edge.Right, Edge.Left, prototypeMap, treeInstances, pendingLines );
CombineOverlaps( islands, coord + new Vector2Int( 0, 1 ), Edge.Bottom, Edge.Top, prototypeMap, treeInstances, pendingLines );
CombineOverlaps( islands, coord + new Vector2Int( 0, -1 ), Edge.Top, Edge.Bottom, prototypeMap, treeInstances, pendingLines );
islands.ForEach( island =>
{
CreateTreeFromIsland( island, prototypeMap, treeInstances, pendingLines );
} );
}
if (createCsv)
......
......@@ -25,6 +25,7 @@ namespace Wander
public string connString = "C:/Data sets/TreesNL.db";
public LayerMask groundLayer;
public List<TreeDBType> types = new();
public int minPixelsForValidTree = 10;
#if UNITY_EDITOR
SqliteConnection sqlConn;
......@@ -67,14 +68,15 @@ namespace Wander
var boundsCpy = bounds;
boundsCpy.center += new Vector3( (float)originRdX, 0, (float)originRdY );
var cmd = sqlConn.CreateCommand();
cmd.CommandText = $"select * from Trees \r\nwhere rdx >= {boundsCpy.min.x} and rdy >= {boundsCpy.min.z} and rdx <= {boundsCpy.max.x} and rdy <= {boundsCpy.max.z}";
cmd.CommandText = $"select * from Trees \r\nwhere rdx >= {boundsCpy.min.x} and rdy >= {boundsCpy.min.z} and rdx <= {boundsCpy.max.x} and rdy <= {boundsCpy.max.z} and num_pixels >= {minPixelsForValidTree}";
var reader = cmd.ExecuteReader();
while (reader.Read())
{
double rdx = reader.GetDouble(0);
double rdy = reader.GetDouble(1);
int type = reader.GetInt32(2);
string crown = reader.GetString(3);
int num_pixels = reader.GetInt32(4);
//string crown = reader.GetString(3);
if (types[type].trees != null && types[type].trees.Count > 0)
{
var prefab = types[type].trees.Random();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment