99.imdk_unity 上传

This commit is contained in:
2025-06-19 10:56:43 +08:00
parent d48c1f1f7b
commit 820c663ab8
651 changed files with 123674 additions and 0 deletions

View File

@@ -0,0 +1,87 @@
/*===============================================================================
Copyright (C) 2024 Immersal - Part of Hexagon. All Rights Reserved.
This file is part of the Immersal SDK.
The Immersal SDK cannot be copied, distributed, or made available to
third-parties for commercial purposes without written permission of Immersal Ltd.
Contact sales@immersal.com for licensing requests.
===============================================================================*/
using Immersal.XR;
using UnityEngine;
namespace Immersal.XR
{
public static class ExtensionMethods
{
public static Matrix4x4 SwitchHandedness(this ref Matrix4x4 b)
{
Matrix4x4 D = Matrix4x4.identity;
D.m00 = -1;
b = D * b * D;
return b;
}
public static Quaternion SwitchHandedness(this ref Quaternion b)
{
Matrix4x4 m = Matrix4x4.Rotate(b);
m.SwitchHandedness();
b = m.rotation;
return b;
}
public static float[] ToFloats(this ref Quaternion q)
{
float[] result = new float[4] { q.x, q.y, q.z, q.w };
return result;
}
public static Vector3 SwitchHandedness(this ref Vector3 b)
{
Matrix4x4 m = Matrix4x4.TRS(b, Quaternion.identity, Vector3.one);
m.SwitchHandedness();
b = m.GetColumn(3);
return b;
}
public static double[] QuaternionsToDoubleMatrix3x3(this XRMap.MapAlignment ma)
{
double[] q = new double[] {ma.qw, ma.qx, ma.qy, ma.qz};
double[] m = new double [] {1, 0, 0, 0, 1, 0, 0, 0, 1}; //identity matrix
// input quaternion should be in WXYZ order
double w = q[0];
double x = q[1];
double y = q[2];
double z = q[3];
double ww = w * w;
double xx = x * x;
double yy = y * y;
double zz = z * z;
double xy = x * y;
double zw = z * w;
double xz = x * z;
double yw = y * w;
double yz = y * z;
double xw = x * w;
double inv = 1.0 / (xx + yy + zz + ww);
m[0] = ( xx - yy - zz + ww) * inv;
m[1] = 2.0 * (xy - zw) * inv;
m[2] = 2.0 * (xz + yw) * inv;
m[3] = 2.0 * (xy + zw) * inv;
m[4] = (-xx + yy - zz + ww) * inv;
m[5] = 2.0 * (yz - xw) * inv;
m[6] = 2.0 * (xz - yw) * inv;
m[7] = 2.0 * (yz + xw) * inv;
m[8] = (-xx - yy + zz + ww) * inv;
return m;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 868f0f079d08249bfbb371a0eaa8dbfe
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,83 @@
/*===============================================================================
Copyright (C) 2024 Immersal - Part of Hexagon. All Rights Reserved.
This file is part of the Immersal SDK.
The Immersal SDK cannot be copied, distributed, or made available to
third-parties for commercial purposes without written permission of Immersal Ltd.
Contact sales@immersal.com for licensing requests.
===============================================================================*/
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using UnityEngine;
namespace Immersal
{
public class ImmersalLogger : MonoBehaviour
{
public enum LoggingLevel
{
All = 0,
Verbose = 1,
ErrorsAndWarnings = 2,
ErrorsOnly = 3,
None = 4
}
public static LoggingLevel Level = LoggingLevel.All;
private const bool m_IncludeCallerName = true;
private const string m_AdditionalPrefix = "";
// Include calling class name in logging messages
private static string ProcessMessage(string message, string filePath = "")
{
if (m_IncludeCallerName)
{
string callerName;
// check if filePath is provided (by System.Runtime.CompilerServices)
if (!string.IsNullOrEmpty(filePath))
{
callerName = System.IO.Path.GetFileNameWithoutExtension(filePath);
}
else
{
// fall back to fetching calling class name from stack with reflection
// note: will give unexpected results when call originates in an async Task
callerName = new StackFrame(2, false).GetMethod().DeclaringType?.Name
?? "Unknown";
}
message = $"[{callerName}] {message}";
}
return $"{m_AdditionalPrefix}{message}";
}
// note: filePath parameter is automagically included by System.Runtime.CompilerServices.CallerFilePath
public static void Log(string message, LoggingLevel messageLevel = LoggingLevel.All, [CallerFilePath] string filePath = "")
{
if (Level > messageLevel) return;
UnityEngine.Debug.Log(ProcessMessage(message, filePath));
}
public static void LogWarning(string message, [CallerFilePath] string filePath = "")
{
if (Level > LoggingLevel.ErrorsAndWarnings) return;
UnityEngine.Debug.LogWarning(ProcessMessage(message, filePath));
}
public static void LogError(string message, [CallerFilePath] string filePath = "")
{
if (Level > LoggingLevel.ErrorsOnly) return;
UnityEngine.Debug.LogError(ProcessMessage(message, filePath));
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 96faf0f52d99e4dd3ba0649f6b0f1e09
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,19 @@
/*===============================================================================
Copyright (C) 2024 Immersal - Part of Hexagon. All Rights Reserved.
This file is part of the Immersal SDK.
The Immersal SDK cannot be copied, distributed, or made available to
third-parties for commercial purposes without written permission of Immersal Ltd.
Contact sales@immersal.com for licensing requests.
===============================================================================*/
using System;
using UnityEngine;
public class InterfaceAttribute : PropertyAttribute
{
public Type TypeOfInterface;
public InterfaceAttribute(Type type) { this.TypeOfInterface = type; }
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: de499560337e94b6799eef1a2fcbd000
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,171 @@
/*===============================================================================
Copyright (C) 2024 Immersal - Part of Hexagon. All Rights Reserved.
This file is part of the Immersal SDK.
The Immersal SDK cannot be copied, distributed, or made available to
third-parties for commercial purposes without written permission of Immersal Ltd.
Contact sales@immersal.com for licensing requests.
===============================================================================*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEngine;
using UnityEngine.Rendering;
namespace Immersal
{
public static class PlyImporter
{
public static Mesh PlyToMesh(byte[] bytes, string name)
{
try
{
using (MemoryStream stream = new MemoryStream(bytes))
{
Mesh mesh = StreamToMesh(stream);
mesh.name = name;
return mesh;
}
}
catch (Exception e)
{
ImmersalLogger.LogError($"Failed importing {name}: {e.Message}");
return null;
}
}
public static Mesh PlyToMesh(string filePath)
{
try
{
var stream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
Mesh mesh = StreamToMesh(stream);
mesh.name = Path.GetFileNameWithoutExtension(filePath);
return mesh;
}
catch (Exception e)
{
ImmersalLogger.LogError($"Failed importing {filePath}: {e.Message}");
return null;
}
}
private static Mesh StreamToMesh(Stream stream)
{
if (!CheckHeader(new StreamReader(stream), out int vertexCount))
throw new ArgumentException("Unexpected header data");
PlyDataBody body = ReadDataBody(new BinaryReader(stream), vertexCount);
var mesh = new Mesh
{
name = "Sparse",
indexFormat = vertexCount > 65535 ? IndexFormat.UInt32 : IndexFormat.UInt16
};
mesh.SetVertices(body.Vertices);
mesh.SetColors(body.Colors);
mesh.SetIndices(
Enumerable.Range(0, vertexCount).ToArray(),
MeshTopology.Points, 0
);
mesh.RecalculateBounds();
mesh.UploadMeshData(true);
return mesh;
}
private static bool CheckHeader(StreamReader reader, out int vertexCount, int maxHeaderLineReads = 15)
{
vertexCount = -1;
int readCount = 0;
int linesRead = 0;
// Magic number line ("ply")
var line = reader.ReadLine();
readCount += line.Length + 1;
if (line != "ply")
throw new ArgumentException("Magic number ('ply') mismatch.");
// check if it's binary/little endian.
line = reader.ReadLine();
readCount += line.Length + 1;
if (line != "format binary_little_endian 1.0")
throw new ArgumentException(
"Invalid data format ('" + line + "'). " +
"Should be binary/little endian.");
while (linesRead < maxHeaderLineReads)
{
line = reader.ReadLine();
linesRead++;
readCount += line.Length + 1;
if (line == "end_header") break;
var col = line.Split();
if (col[0] == "element")
{
if (col[1] == "vertex")
{
vertexCount = Convert.ToInt32(col[2]);
}
}
}
// Rewind the stream back to the exact position of the reader.
reader.BaseStream.Position = readCount;
return vertexCount > -1;
}
private static PlyDataBody ReadDataBody(BinaryReader reader, int vertexCount)
{
PlyDataBody data = new PlyDataBody(vertexCount);
for (var i = 0; i < vertexCount; i++)
{
float x = reader.ReadSingle();
float y = reader.ReadSingle();
float z = reader.ReadSingle();
Byte r = reader.ReadByte();
Byte g = reader.ReadByte();
Byte b = reader.ReadByte();
//a = reader.ReadByte();
Byte a = Byte.MaxValue;
data.AddPoint(-x, y, z, r, g, b, a);
}
return data;
}
}
public class PlyDataBody
{
public List<Vector3> Vertices;
public List<Color32> Colors;
public PlyDataBody(int vertexCount)
{
Vertices = new List<Vector3>(vertexCount);
Colors = new List<Color32>(vertexCount);
}
public void AddPoint(
float x, float y, float z,
byte r, byte g, byte b, byte a
)
{
Vertices.Add(new Vector3(x, y, z));
Colors.Add(new Color32(r, g, b, a));
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a6e2d23c28b294a9197bb2445580a9f7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,17 @@
/*===============================================================================
Copyright (C) 2024 Immersal - Part of Hexagon. All Rights Reserved.
This file is part of the Immersal SDK.
The Immersal SDK cannot be copied, distributed, or made available to
third-parties for commercial purposes without written permission of Immersal Ltd.
Contact sales@immersal.com for licensing requests.
===============================================================================*/
using UnityEngine;
public class ReadOnlyAttribute : PropertyAttribute
{
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fdc229f6d17eb41288b444e1c60d6309
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: