diff --git a/Assets/Scripts/Loading/BinaryDownloadProvider.cs b/Assets/Scripts/Loading/BinaryDownloadProvider.cs index 24936e4..4055835 100644 --- a/Assets/Scripts/Loading/BinaryDownloadProvider.cs +++ b/Assets/Scripts/Loading/BinaryDownloadProvider.cs @@ -26,7 +26,7 @@ public BinaryDownloadProvider(Dictionary content) /// /// URI to request /// Object representing the request - public async Task Request(Uri url) + public async Task RequestAsync(Uri url) { var req = new AwaitableDownload(url); await req.WaitAsync(); @@ -39,7 +39,7 @@ public async Task Request(Uri url) /// URI to request /// If true, resulting texture is not CPU readable (uses less memory) /// Object representing the request - public async Task RequestTexture(Uri url, bool nonReadable) + public async Task RequestTextureAsync(Uri url, bool nonReadable, bool forceLinear) { var fileName = Path.GetFileName(url.LocalPath); var file = _content[fileName]; @@ -159,10 +159,6 @@ public void Dispose() public class AwaitableTextureDownload : AwaitableDownload, ITextureDownload { - - /// - public Texture2D Texture => (m_Request?.downloadHandler as DownloadHandlerTexture)?.texture; - /// /// Parameter-less constructor, required for inheritance. /// @@ -196,5 +192,17 @@ void Init(Uri url, bool nonReadable) m_Request = CreateRequest(url, nonReadable); m_AsyncOperation = m_Request.SendWebRequest(); } + + /// + public IDisposableTexture GetTexture(bool linear) + { + return (m_Request?.downloadHandler as DownloadHandlerTexture)?.texture.ToDisposableTexture(); + } + } + + internal static class DisposableTextureExtensions + { + internal static IDisposableTexture ToDisposableTexture(this Texture2D texture2D) => + new NonReusableTexture(texture2D); } } \ No newline at end of file diff --git a/Assets/Scripts/Loading/GLTFLoader.cs b/Assets/Scripts/Loading/GLTFLoader.cs index 4cb543f..ce43f48 100644 --- a/Assets/Scripts/Loading/GLTFLoader.cs +++ b/Assets/Scripts/Loading/GLTFLoader.cs @@ -42,7 +42,7 @@ public static async Task LoadModel(BodyShape bodyShape, EntityDefin root.SetActive(false); root.transform.SetParent(parent, false); - var instantiator = new DclGameObjectInstantiator(importer, root.transform); + var instantiator = new GameObjectInstantiator(importer, root.transform); await importer.InstantiateSceneAsync(instantiator); Sanitize(root.transform); diff --git a/Assets/Scripts/Loading/ToonMaterialGenerator.cs b/Assets/Scripts/Loading/ToonMaterialGenerator.cs index 4d46591..dbd1701 100644 --- a/Assets/Scripts/Loading/ToonMaterialGenerator.cs +++ b/Assets/Scripts/Loading/ToonMaterialGenerator.cs @@ -2,10 +2,8 @@ using GLTFast; using GLTFast.Logging; using GLTFast.Materials; -using GLTFast.Schema; using UnityEngine; using UnityEngine.Rendering; -using Material = UnityEngine.Material; namespace Loading { @@ -37,7 +35,7 @@ public ToonMaterialGenerator(AvatarColors avatarColors) //_avatarColors = avatarColors; } - public Material GenerateMaterial(MaterialBase gltfMaterial, IGltfReadable gltf, + public Material GenerateMaterial(int materialIndex, GLTFast.Schema.Material gltfMaterial, IGltfReadable gltf, bool pointsSupport = false) { var isFacialFeature = IsFacialFeature(gltfMaterial.name); @@ -45,20 +43,20 @@ public Material GenerateMaterial(MaterialBase gltfMaterial, IGltfReadable gltf, { name = gltfMaterial.name }; // Base color and texture - var baseColor = gltfMaterial.PbrMetallicRoughness.BaseColor; + var baseColor = gltfMaterial.pbrMetallicRoughness.BaseColor; mat.SetColor(BASE_COLOR_ID, baseColor); - if (gltfMaterial.PbrMetallicRoughness.BaseColorTexture.index != -1) + if (gltfMaterial.pbrMetallicRoughness.baseColorTexture.index != -1) { - mat.SetTexture(MAIN_TEX_ID, gltf.GetTexture(gltfMaterial.PbrMetallicRoughness.BaseColorTexture.index)); + mat.SetTexture(MAIN_TEX_ID, gltf.GetTexture(gltfMaterial.pbrMetallicRoughness.baseColorTexture.index)); } // Emission mat.SetColor(EMISSIVE_COLOR_ID, gltfMaterial.Emissive * EMISSIVE_MAGIC_NUMBER); - if (gltfMaterial.EmissiveTexture.index != -1) + if (gltfMaterial.emissiveTexture.index != -1) { - mat.SetTexture(EMISSIVE_TEX_ID, gltf.GetTexture(gltfMaterial.EmissiveTexture.index)); + mat.SetTexture(EMISSIVE_TEX_ID, gltf.GetTexture(gltfMaterial.emissiveTexture.index)); } // Alpha diff --git a/Packages/manifest.json b/Packages/manifest.json index 5e41246..029cfee 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -1,6 +1,6 @@ { "dependencies": { - "com.atteneder.gltfast": "https://github.com/decentraland/unity-gltf.git#chore/gltfast-update", + "com.atteneder.gltfast": "https://github.com/decentraland/unity-gltf.git", "com.decentraland.unity-shared-dependencies": "git@github.com:decentraland/unity-shared-dependencies.git#main", "com.unity.cinemachine": "3.1.4", "com.unity.ide.rider": "3.0.39", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index f83cf67..91437b8 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -1,24 +1,23 @@ { "dependencies": { "com.atteneder.gltfast": { - "version": "https://github.com/decentraland/unity-gltf.git#chore/gltfast-update", + "version": "https://github.com/decentraland/unity-gltf.git", "depth": 0, "source": "git", "dependencies": { "com.unity.modules.jsonserialize": "1.0.0", "com.unity.modules.unitywebrequest": "1.0.0", "com.unity.mathematics": "1.2.6", - "com.unity.burst": "1.8.24", - "com.unity.collections": "1.2.4" + "com.unity.burst": "1.6.6" }, - "hash": "59e20d09a7665395eb9141180c55abdce61fdbc7" + "hash": "e4587451389b6cf93b084ae434d0cc3d32a45076" }, "com.decentraland.unity-shared-dependencies": { "version": "git@github.com:decentraland/unity-shared-dependencies.git#main", "depth": 0, "source": "git", "dependencies": {}, - "hash": "0132f23fb5d1bfa1634a872ef28e131067df7a69" + "hash": "f040030e82c51bdddce67ae18149e22b5b4c4c0d" }, "com.unity.burst": { "version": "1.8.28", @@ -42,7 +41,7 @@ }, "com.unity.collections": { "version": "6.4.0", - "depth": 1, + "depth": 2, "source": "builtin", "dependencies": { "com.unity.burst": "1.8.23", @@ -94,7 +93,7 @@ }, "com.unity.nuget.mono-cecil": { "version": "1.11.6", - "depth": 2, + "depth": 3, "source": "registry", "dependencies": {}, "url": "https://packages.unity.com" @@ -183,7 +182,7 @@ }, "com.unity.test-framework.performance": { "version": "3.2.0", - "depth": 2, + "depth": 3, "source": "registry", "dependencies": { "com.unity.test-framework": "1.1.33",