Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Fixed PLY header parsing to count only vertex element properties. The package now supports PLY files exported by Apple's [ml-sharp](https://github.com/apple/ml-sharp). ([#33](https://github.com/wuyize25/gsplat-unity/pull/33) by [@TakashiYoshinaga](https://github.com/TakashiYoshinaga))

- Fixed compilation errors on Unity 6.4 and later caused by the obsoletion of `Object.GetInstanceID()`, while preserving compatibility with older Unity versions. ([#41](https://github.com/wuyize25/gsplat-unity/pull/41) by [@RuiCarvalhoCouto](https://github.com/RuiCarvalhoCouto))

## [1.3.0] - 2026-05-23

### Added
Expand Down
12 changes: 6 additions & 6 deletions Runtime/GsplatRendererImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class GsplatRendererImpl
GsplatAsset m_gsplatAsset;
public uint m_remainingCount = 0;
public Bounds m_bounds;
int m_gsplatAssetID;
ulong m_gsplatAssetID;

public GsplatResource GsplatResource;
public GraphicsBuffer OrderBuffer { get; private set; }
Expand All @@ -39,15 +39,15 @@ public class GsplatRendererImpl
uint m_sortsBeforeRecomputeCutouts = 0;
public bool ComputeSortRequired = true;
public bool ComputeCutoutsRequired = true;
Dictionary<int, (Vector3, Vector3)> m_prevCamTransforms;
Dictionary<ulong, (Vector3, Vector3)> m_prevCamTransforms;

GsplatCutout.ShaderData[] m_cutoutsData;
uint m_prevSplatCount;

public GsplatRendererImpl(uint splatCount)
{
SplatCount = splatCount;
m_prevCamTransforms = new Dictionary<int, (Vector3, Vector3)>();
m_prevCamTransforms = new Dictionary<ulong, (Vector3, Vector3)>();
CreateResources(splatCount);
CreatePropertyBlock();
}
Expand Down Expand Up @@ -134,7 +134,7 @@ public void DispatchInitOrder(GsplatCutout[] cutouts, Matrix4x4 matrixWorld, boo
public void BindGsplatAsset(GsplatAsset gsplatAsset, bool asyncUpload = false)
{
Debug.Assert(m_gsplatAssetID == 0);
m_gsplatAssetID = gsplatAsset.GetInstanceID();
m_gsplatAssetID = GsplatUtils.GetObjectId(gsplatAsset);
m_gsplatAsset = gsplatAsset;
GsplatResource = GsplatResourceManager.Get(gsplatAsset);
gsplatAsset.SetupMaterialPropertyBlock(m_propertyBlock, GsplatResource);
Expand Down Expand Up @@ -193,7 +193,7 @@ public void RefreshOnCameraMove()
{
foreach (var cam in Camera.allCameras)
{
var id = cam.GetInstanceID();
var id = GsplatUtils.GetObjectId(cam);
if (m_prevCamTransforms.TryGetValue(id, out (Vector3, Vector3) prevCamTransform))
{
(Vector3 prevCamPos, Vector3 prevCamRot) = prevCamTransform;
Expand All @@ -209,7 +209,7 @@ public void RefreshOnCameraMove()
}
else
{
m_prevCamTransforms.Add(cam.GetInstanceID(), (cam.transform.position, cam.transform.eulerAngles));
m_prevCamTransforms.Add(id, (cam.transform.position, cam.transform.eulerAngles));
ForceRefresh();
}
}
Expand Down
17 changes: 11 additions & 6 deletions Runtime/GsplatResourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ class Cache
public int RefCount;
}

static readonly Dictionary<int, Cache> k_resourceCache = new();
static readonly Dictionary<ulong, Cache> k_resourceCache = new();

public static GsplatResource Get(GsplatAsset asset)
{
var key = asset.GetInstanceID();
var key = GsplatUtils.GetObjectId(asset);
if (k_resourceCache.TryGetValue(key, out var cache))
{
cache.RefCount++;
Expand All @@ -33,14 +33,19 @@ public static GsplatResource Get(GsplatAsset asset)

public static void Release(GsplatAsset asset)
{
Release(asset.GetInstanceID());
Release(GsplatUtils.GetObjectId(asset));
}

public static void Release(int instanceID)
{
if (instanceID == 0)
Release(unchecked((uint)instanceID));
}

internal static void Release(ulong objectID)
{
if (objectID == 0)
return;
if (!k_resourceCache.TryGetValue(instanceID, out var cache))
if (!k_resourceCache.TryGetValue(objectID, out var cache))
{
Debug.LogWarning("Trying to release a GPU resource that is not cached.");
return;
Expand All @@ -49,7 +54,7 @@ public static void Release(int instanceID)
cache.RefCount--;
if (cache.RefCount != 0) return;
cache.Resource.Dispose();
k_resourceCache.Remove(instanceID);
k_resourceCache.Remove(objectID);
}
}
}
6 changes: 3 additions & 3 deletions Runtime/GsplatSorter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void Dispose()
readonly HashSet<IGsplat> m_gsplats = new();
readonly HashSet<Camera> m_camerasInjected = new();
readonly List<IGsplat> m_activeGsplats = new();
readonly HashSet<int> m_warnedUncompressed = new();
readonly HashSet<ulong> m_warnedUncompressed = new();
GsplatSortPass m_sortPass;
public const string k_passName = "SortGsplats";
const string k_depthPassName = "Gsplat.ComputeDepth";
Expand Down Expand Up @@ -109,7 +109,7 @@ public void UnregisterGsplat(IGsplat gsplat)
return;

if (gsplat is UnityEngine.Object obj)
m_warnedUncompressed.Remove(obj.GetInstanceID());
m_warnedUncompressed.Remove(GsplatUtils.GetObjectId(obj));

m_globalRenderer.MarkGlobalBuffersDirty();

Expand Down Expand Up @@ -158,7 +158,7 @@ bool CanRenderGlobally()
{
if (gs.GsplatResource is GsplatResourceSpark) continue;
var obj = gs as UnityEngine.Object;
var id = obj ? obj.GetInstanceID() : 0;
var id = obj ? GsplatUtils.GetObjectId(obj) : 0;
if (m_warnedUncompressed.Add(id))
Debug.LogWarning(
$"[GsplatSorter] '{obj?.name}' uses an uncompressed asset; global sort requires every active renderer to use SPARK compression. Disabling global sort for this scene — all renderers fall back to per-renderer rendering.");
Expand Down
9 changes: 9 additions & 0 deletions Runtime/GsplatUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ public static class GsplatUtils
public const string k_PackagePath = "Packages/wu.yize.gsplat/";
public static readonly Version k_Version = new("1.4.0");

internal static ulong GetObjectId(UnityEngine.Object obj)
{
#if UNITY_6000_4_OR_NEWER
return EntityId.ToULong(obj.GetEntityId());
#else
return unchecked((uint)obj.GetInstanceID());
#endif
}

// radix sort etc. friendly, see http://stereopsis.com/radix.html
public static uint FloatToSortableUint(float f)
{
Expand Down