Skip to content
20 changes: 14 additions & 6 deletions Assets/Scripts/Loading/BinaryDownloadProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public BinaryDownloadProvider(Dictionary<string, string> content)
/// </summary>
/// <param name="url">URI to request</param>
/// <returns>Object representing the request</returns>
public async Task<IDownload> Request(Uri url)
public async Task<IDownload> RequestAsync(Uri url)
{
var req = new AwaitableDownload(url);
await req.WaitAsync();
Expand All @@ -39,7 +39,7 @@ public async Task<IDownload> Request(Uri url)
/// <param name="url">URI to request</param>
/// <param name="nonReadable">If true, resulting texture is not CPU readable (uses less memory)</param>
/// <returns>Object representing the request</returns>
public async Task<ITextureDownload> RequestTexture(Uri url, bool nonReadable)
public async Task<ITextureDownload> RequestTextureAsync(Uri url, bool nonReadable, bool forceLinear)
{
var fileName = Path.GetFileName(url.LocalPath);
var file = _content[fileName];
Expand Down Expand Up @@ -159,10 +159,6 @@ public void Dispose()

public class AwaitableTextureDownload : AwaitableDownload, ITextureDownload
{

/// <inheritdoc />
public Texture2D Texture => (m_Request?.downloadHandler as DownloadHandlerTexture)?.texture;

/// <summary>
/// Parameter-less constructor, required for inheritance.
/// </summary>
Expand Down Expand Up @@ -196,5 +192,17 @@ void Init(Uri url, bool nonReadable)
m_Request = CreateRequest(url, nonReadable);
m_AsyncOperation = m_Request.SendWebRequest();
}

/// <inheritdoc />
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);
}
}
2 changes: 1 addition & 1 deletion Assets/Scripts/Loading/GLTFLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static async Task<LoadedModel> 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);
Expand Down
14 changes: 6 additions & 8 deletions Assets/Scripts/Loading/ToonMaterialGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -37,28 +35,28 @@ 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);
var mat = new Material(isFacialFeature ? CommonAssets.FacialFeaturesMaterial : CommonAssets.AvatarMaterial)
{ 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
Expand Down
2 changes: 1 addition & 1 deletion Packages/manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
15 changes: 7 additions & 8 deletions Packages/packages-lock.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -42,7 +41,7 @@
},
"com.unity.collections": {
"version": "6.4.0",
"depth": 1,
"depth": 2,
"source": "builtin",
"dependencies": {
"com.unity.burst": "1.8.23",
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down
Loading