Skip to content

Commit

Permalink
Merge pull request #3 from ViRGIS-Team/2.5.0
Browse files Browse the repository at this point in the history
2.5.0
  • Loading branch information
runette authored Feb 6, 2023
2 parents 9027cc9 + 184190d commit efc6590
Show file tree
Hide file tree
Showing 11 changed files with 672 additions and 380 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
This plugin will be updated as and when new versions of PDAL are released and will use the version numbers from PDAL.

2.2.0+3 :
# Version 2.5.0

Updates PDAL to version 2.5.0 using pdalc version 2.2.0 to get over the Pipeline Executor deprecation.

This version also moves the conda build to an Asset Post Processor and standardizes assembly names - so there may/will be minor changes in how it operates - including if other assemblies reference this assembly directly.

This version also moves the processing in `BakedPointCloud` to the Unity Job System for faster processing.

# 2.2.0+3 :

- Fixes Bug whne there is a space in the project name
50 changes: 26 additions & 24 deletions Editor/Plugins/install_scripts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,40 @@
using System;
using Debug = UnityEngine.Debug;

#if UNITY_EDITOR
namespace Pdal {
public class Install{
public class Install: AssetPostprocessor
{
const string pdalcVersion = "2.2.0";

const string pdalcVersion = "2.1.1";

[InitializeOnLoadMethod]
static void OnProjectLoadedinEditor()
private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
if (!SessionState.GetBool("PdalInitDone", false))
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();

EditorUtility.DisplayProgressBar("Restoring Conda Package", "PDAL", 0);
EditorUtility.DisplayProgressBar("Restoring Conda Package", "PDAL", 0);

if (Application.isEditor) {
try
{
Config config = new Config();
string currentVersion = config.Version;
}
catch (Exception e)
if (Application.isEditor)
{
Debug.Log($"Error in Conda Package PDAL : {e.ToString()}");
UpdatePackage();
AssetDatabase.Refresh();
try
{
Config config = new Config();
string currentVersion = config.Version;
}
catch (Exception e)
{
Debug.Log($"Error in Conda Package PDAL : {e.ToString()}");
UpdatePackage();
AssetDatabase.Refresh();
};
};
};

EditorUtility.ClearProgressBar();
stopwatch.Stop();
Debug.Log($"Pdal refresh took {stopwatch.Elapsed.TotalSeconds} seconds");
EditorUtility.ClearProgressBar();
stopwatch.Stop();
Debug.Log($"Pdal refresh took {stopwatch.Elapsed.TotalSeconds} seconds");
}
SessionState.SetBool("PdalInitDone", true);
}


Expand All @@ -52,4 +55,3 @@ static void UpdatePackage()
}
}
}
#endif
107 changes: 107 additions & 0 deletions Runtime/Scripts/BakedMesh.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
using g3;
using System;
using System.Threading.Tasks;
using Unity.Collections;
using Unity.Jobs;
using UnityEngine;
using Unity.Burst;


namespace Pdal
{
/// <summary>
/// Class for Holding and Manipulating Meshes Loaded Using PDAL
/// </summary>
public class BakedMesh
{

public DMesh3 Dmesh;
public BakedMesh() { }

/// <summary>
/// Load a PointView as a Mesh
/// </summary>
/// <param name="view">Pointview</param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public async static Task<BakedMesh> Initialize(PointView view)
{
BakedPointCloud bpc = await BakedPointCloud.Initialize(view);
NativeArray<byte> Data = new(view.GetPackedMesh(out ulong dataSize), Allocator.Persistent);
if (dataSize == 0) throw new Exception("BakedMesh : No Mesh Found");

ulong sizeTri = dataSize / 12;

NativeArray<Int32> Tris = new(new Int32[sizeTri * 3], Allocator.Persistent);

DecodeMesh dm = new() {
Data = Data,
Tris = Tris,
};

JobHandle jh = dm.Schedule((int)sizeTri, 100);
jh.Complete();

NativeArray<Color> positions = bpc.PositionMap.GetRawTextureData<Color>();
NativeArray<Color32> colors = bpc.ColorMap.GetRawTextureData<Color32>();

double[] vertices= new double[bpc.PointCount * 3 ];


for (int i = 0; i < bpc.PointCount; i++)
{
Color position = positions[i];
vertices[3 * i] = position.r;
vertices[3 * i + 1] = position.g;
vertices[3 * i + 2] = position.b;
}

// Now we can make the Mesh
BakedMesh bm = new()
{
Dmesh = DMesh3Builder.Build<double, int, int>(vertices, Tris)
};
if (colors.Length > 0)
{
bm.Dmesh.EnableVertexColors(new Vector3f());
foreach (int idx in bm.Dmesh.VertexIndices())
{
bm.Dmesh.SetVertexColor(idx, new Vector3f(colors[idx].r / 256, colors[idx].g / 256, colors[idx].b / 256));
}
}

positions.Dispose();
colors.Dispose();
Data.Dispose();
Tris.Dispose();
return bm;
}

/// <summary>
/// Job System Job that is used to iterate the Vertices
/// </summary>
[BurstCompile]
public struct DecodeMesh : IJobParallelFor
{
[ReadOnly]
public NativeArray<byte> Data;

[NativeDisableParallelForRestriction]
public NativeArray<Int32> Tris;

public void Execute(int job)
{
int pointer = job * 3;
int index = pointer * 4;

if (index + 12 > Data.Length)
return;
Tris[pointer] = (int)Data.ReinterpretLoad<UInt32>(index);
Tris[pointer + 1] = (int)Data.ReinterpretLoad<UInt32>(index + 4);
Tris[pointer + 2] = (int)Data.ReinterpretLoad<UInt32>(index + 8);
}
}
}
}


11 changes: 11 additions & 0 deletions Runtime/Scripts/BakedMesh.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit efc6590

Please sign in to comment.