Skip to content

Commit

Permalink
Merge pull request #34 from ViRGIS-Team/update
Browse files Browse the repository at this point in the history
Fix CalculateMapUV
  • Loading branch information
runette authored Jul 22, 2024
2 parents 581d46b + 43eb58f commit 4d0f680
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
28 changes: 17 additions & 11 deletions Runtime/Scripts/GdalExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE

using VirgisGeometry;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Unity.Collections;
Expand Down Expand Up @@ -124,13 +125,17 @@ public static void CalculateMapUVs(this DMesh3 dMesh, Dataset raster)
throw new Exception("Could not get a GeoTransform");
}

NativeArray<Vector2d> UV = new NativeArray<Vector2d>(dMesh.VertexCount, Allocator.Persistent);
IEnumerable<double3> v = dMesh.Vertices().Cast<double3>();

NativeArray<Vector3d> vertices = new NativeArray<Vector3d>(dMesh.Vertices().ToArray<Vector3d>(), Allocator.Persistent);
NativeArray<double2> UV = new (dMesh.VertexCount, Allocator.Persistent);

MapUV uvJob = new();
uvJob.transform = math.inverse(gtRaw.ToTransform());
uvJob.vertices = vertices;
NativeArray<double3> vertices = new (v.ToArray(), Allocator.Persistent);

MapUV uvJob = new()
{
transform = math.inverse(gtRaw.ToTransform()),
vertices = vertices
};

JobHandle jh = uvJob.Schedule(vertices.Length, 10);
jh.Complete();
Expand Down Expand Up @@ -169,23 +174,24 @@ public static Task<int> CalculateMapUVsAsync(this DMesh3 dMesh, Dataset raster)
struct MapUV : IJobParallelFor
{
[ReadOnly]
public NativeArray<Vector3d> vertices;
public NativeArray<double3> vertices;

[ReadOnly]
public Matrix3d transform;
public double3x3 transform;


public NativeArray<Vector2d> UV;
public NativeArray<double2> UV;


public void Execute(int job)
{
Vector3d vertex = vertices[job];
double3 vertex = vertices[job];

Vector3d flatvert = new(vertex.x, vertex.z, 1);
double3 flatvert = new(vertex.x, vertex.z, 1);

Vector2d uv = (Vector2d)(transform * flatvert) ;
double3 uv = math.mul(transform, flatvert);

UV[job] = new double2(uv.x, uv.y);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.virgis.gdal",
"version": "3.9.1",
"version": "3.9.2",
"displayName": "Gdal",
"description": "Open-Source Geospatial Data Translation LIbrary",
"unity": "2018.1",
Expand Down

0 comments on commit 4d0f680

Please sign in to comment.