Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: preview non-released collections #3097

Draft
wants to merge 22 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
9fa52af
first messy experimentations
pravusjif Jan 10, 2025
4fa8039
more experimentation: finally being able to parse lambda result data
pravusjif Jan 13, 2025
5895759
created new interface for lambda response
pravusjif Jan 14, 2025
0bda7f9
cleaned up and improved lambda response structures
pravusjif Jan 14, 2025
fa17aca
improved lambda response structures to be used on child classes
pravusjif Jan 14, 2025
2d6ccce
minor reorganization
pravusjif Jan 14, 2025
88a3b95
started lambda response conversion to WearableDTO
pravusjif Jan 14, 2025
f62a9b0
finally managed to load WearableDTO for user; Moving onto wearable as…
pravusjif Jan 15, 2025
99a48ed
configured builder api content url and injected it into WearablePlugi…
pravusjif Jan 15, 2025
e8b88d5
finally managed to download builder wearable thumbnail correctly
pravusjif Jan 16, 2025
14e1a68
Started hacking to have raw GLTF loading globally...
pravusjif Jan 20, 2025
0c5f782
Continued experimentation for loading RAW GTLF wearables
pravusjif Jan 21, 2025
540b7b7
removed problematic check
pravusjif Jan 21, 2025
0f47ae8
got RAW GLTF wearable to load, problems with builder-api response fil…
pravusjif Jan 22, 2025
88d4a8a
Merge branch 'dev' of github.com:decentraland/unity-explorer into fea…
pravusjif Jan 22, 2025
fe94863
fixed wrong 'missing content' check
pravusjif Jan 22, 2025
4918cdd
first (failed) attempt at changing wearable raw GLTF textures compres…
pravusjif Jan 24, 2025
6010ad7
compression seems to be working but BC7 cannot be compressed in runti…
pravusjif Jan 24, 2025
c5b63ff
added TextureArrayHandlers for RGBA32 and enforced every raw gltf wea…
pravusjif Jan 28, 2025
3211245
Merge branch 'dev' of github.com:decentraland/unity-explorer into fea…
pravusjif Jan 28, 2025
5f7af24
Merge branch 'dev' of github.com:decentraland/unity-explorer into fea…
pravusjif Jan 28, 2025
ee18649
removed some commented out code
pravusjif Jan 28, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ private static (Material avatarMaterial, TextureArraySlot?[] slots, int shaderId
PoolMaterialSetup poolMaterialSetup = poolHandler.GetMaterialPool(shaderId);
Material avatarMaterial = poolMaterialSetup.Pool.Get();

// DEBUG
if (originalMaterial.enabledKeywords.Length == 0)
{
// avatarMaterial = originalMaterial;
/*originalMaterial.EnableKeyword("_MAIN_LIGHT_SHADOWS_CASCADE");
originalMaterial.EnableKeyword("_ADDITIONAL_LIGHT_SHADOWS");
originalMaterial.EnableKeyword("_SHADOWS_SOFT");
originalMaterial.EnableKeyword("_FORWARD_PLUS");*/
Debug.Log("...");
}

var baseColor = originalMaterial.GetColor(BASE_COLOR);
avatarMaterial.SetColor(BASE_COLOR, baseColor);
avatarMaterial.renderQueue = (int)RenderQueue.Geometry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public static class TextureArrayConstants
public const TextureFormat DEFAULT_BASEMAP_TEXTURE_FORMAT = TextureFormat.BC7;
public const TextureFormat DEFAULT_NORMALMAP_TEXTURE_FORMAT = TextureFormat.BC5;
public const TextureFormat DEFAULT_EMISSIVEMAP_TEXTURE_FORMAT = TextureFormat.BC7;
public const TextureFormat DEFAULT_RAW_GLTF_TEXTURE_FORMAT = TextureFormat.RGBA32;

// Some textures are less probably contained in the original material
// so we can use a smaller starting array size for them
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Pool;
using static DCL.AvatarRendering.AvatarShape.Rendering.TextureArray.TextureArrayConstants;

namespace DCL.AvatarRendering.AvatarShape.Rendering.TextureArray
{
Expand Down Expand Up @@ -37,10 +38,14 @@ public void ReleaseSlots(TextureArraySlot?[] slots)
TextureArrayMapping mapping = mappings[i];
// Check if the texture is present in the original material
var tex = originalMaterial.GetTexture(mapping.OriginalTextureID) as Texture2D;
if (tex && tex.format == mapping.Handler.GetTextureFormat())
var handlerFormat = mapping.Handler.GetTextureFormat();
if (tex && tex.format == handlerFormat)
results[i] = mapping.Handler.SetTexture(targetMaterial, tex, new Vector2Int(tex.width, tex.height));
else
mapping.Handler.SetDefaultTexture(targetMaterial, mapping.DefaultFallbackResolution);
else if (tex == null
|| handlerFormat == DEFAULT_BASEMAP_TEXTURE_FORMAT
|| handlerFormat == DEFAULT_NORMALMAP_TEXTURE_FORMAT
|| handlerFormat == DEFAULT_EMISSIVEMAP_TEXTURE_FORMAT)
mapping.Handler.SetDefaultTexture(targetMaterial, mapping.DefaultFallbackResolution);
}

return results;
Expand All @@ -53,11 +58,14 @@ public void ReleaseSlots(TextureArraySlot?[] slots)
for (var i = 0; i < mappings.Count; i++)
{
TextureArrayMapping mapping = mappings[i];
var handlerFormat = mapping.Handler.GetTextureFormat();

if (textures.TryGetValue(mapping.OriginalTextureID, out var texture))
results[i] = mapping.Handler.SetTexture(targetMaterial, texture as Texture2D, new Vector2Int(texture.width, texture.height));
else
mapping.Handler.SetDefaultTexture(targetMaterial, mapping.DefaultFallbackResolution, defaultSlotIndexUsed);
else if (handlerFormat == DEFAULT_BASEMAP_TEXTURE_FORMAT
|| handlerFormat == DEFAULT_NORMALMAP_TEXTURE_FORMAT
|| handlerFormat == DEFAULT_EMISSIVEMAP_TEXTURE_FORMAT)
mapping.Handler.SetDefaultTexture(targetMaterial, mapping.DefaultFallbackResolution, defaultSlotIndexUsed);
}

return results;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ private TextureArrayContainer CreateToon(IReadOnlyList<int> defaultResolutions)
return new TextureArrayContainer(
new TextureArrayMapping[]
{
// Asset Bundle Wearables (BC7/BC5)
new (new TextureArrayHandler(MAIN_TEXTURE_ARRAY_SIZE, MAINTEX_ARR_SHADER_INDEX, MAINTEX_ARR_TEX_SHADER, defaultResolutions, DEFAULT_BASEMAP_TEXTURE_FORMAT, defaultTextures),
MAINTEX_ORIGINAL_TEXTURE, MAIN_TEXTURE_RESOLUTION),
new (new TextureArrayHandler(NORMAL_TEXTURE_ARRAY_SIZE, NORMAL_MAP_TEX_ARR_INDEX, NORMAL_MAP_TEX_ARR, defaultResolutions, DEFAULT_NORMALMAP_TEXTURE_FORMAT, defaultTextures),
Expand All @@ -47,6 +48,14 @@ private TextureArrayContainer CreateToon(IReadOnlyList<int> defaultResolutions)

// new (new TextureArrayHandler(OTHER_TEXTURE_ARRAY_SIZE, METALLIC_GLOSS_MAP_ARR_SHADER_ID, METALLIC_GLOSS_MAP_ARR_TEX_SHADER_ID), METALLIC_GLOSS_MAP_ORIGINAL_TEXTURE_ID),
// new (new TextureArrayHandler(OTHER_TEXTURE_ARRAY_SIZE, OCCLUSION_MAP_ARR_SHADER_ID, OCCLUSION_MAP_ARR_TEX_SHADER_ID), OCCLUSION_MAP_ORIGINAL_TEXTURE_ID),

// Raw GLTF Wearables (RGBA32)
new (new TextureArrayHandler(MAIN_TEXTURE_ARRAY_SIZE, MAINTEX_ARR_SHADER_INDEX, MAINTEX_ARR_TEX_SHADER, defaultResolutions, DEFAULT_RAW_GLTF_TEXTURE_FORMAT),
MAINTEX_ORIGINAL_TEXTURE, MAIN_TEXTURE_RESOLUTION),
new (new TextureArrayHandler(NORMAL_TEXTURE_ARRAY_SIZE, NORMAL_MAP_TEX_ARR_INDEX, NORMAL_MAP_TEX_ARR, defaultResolutions, DEFAULT_RAW_GLTF_TEXTURE_FORMAT),
BUMP_MAP_ORIGINAL_TEXTURE_ID, NORMAL_TEXTURE_RESOLUTION),
new (new TextureArrayHandler(EMISSION_TEXTURE_ARRAY_SIZE, EMISSIVE_MAP_TEX_ARR_INDEX, EMISSIVE_MAP_TEX_ARR, defaultResolutions, DEFAULT_RAW_GLTF_TEXTURE_FORMAT),
EMISSION_MAP_ORIGINAL_TEXTURE_ID, EMISSION_TEXTURE_RESOLUTION),
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ public class TextureArrayHandler
private readonly int initialCapacityForEachResolution;
private readonly TextureFormat textureFormat;

private readonly IReadOnlyDictionary<TextureArrayKey, Texture> defaultTextures;
private readonly IReadOnlyDictionary<TextureArrayKey, Texture>? defaultTextures;

public TextureArrayHandler(
int minArraySize,
int arrayID,
int textureID,
IReadOnlyList<int> defaultResolutions,
TextureFormat textureFormat,
IReadOnlyDictionary<TextureArrayKey, Texture> defaultTextures,
IReadOnlyDictionary<TextureArrayKey, Texture>? defaultTextures = null,
int initialCapacityForEachResolution = PoolConstants.AVATARS_COUNT)
{
this.minArraySize = minArraySize;
Expand Down Expand Up @@ -76,32 +76,37 @@ private TextureArraySlotHandler CreateHandler(TextureArrayResolutionDescriptor d
handlersByResolution[resolution] = slotHandler;

// When the handler is created initialize the default texture
for (int i = 0; i < defaultTextures.Count; ++i)
if (defaultTextures != null)
{
if (defaultTextures.TryGetValue(new TextureArrayKey(textureID, resolution, i), out var defaultTexture))
for (int i = 0; i < defaultTextures.Count; ++i)
{
var defaultSlot = slotHandler.GetNextFreeSlot();
Graphics.CopyTexture(defaultTexture, srcElement: 0, srcMip: 0, defaultSlot.TextureArray, dstElement: defaultSlot.UsedSlotIndex, dstMip: 0);
if (defaultTextures.TryGetValue(new TextureArrayKey(textureID, resolution, i), out var defaultTexture))
{
var defaultSlot = slotHandler.GetNextFreeSlot();
Graphics.CopyTexture(defaultTexture, srcElement: 0, srcMip: 0, defaultSlot.TextureArray, dstElement: defaultSlot.UsedSlotIndex, dstMip: 0);
}
}
}

return slotHandler;
}


private TextureArraySlotHandler CreateHandler(Vector2Int resolution)
{
//We are creating a considerably smaller array for non square resolutions. Shouldn't be a common case
var slotHandler = new TextureArraySlotHandler(resolution, resolution.x == resolution.y ? minArraySize : minArraySize / 10, initialCapacityForEachResolution, textureFormat);
handlersByResolution[resolution] = slotHandler;

// When the handler is created initialize the default texture
for (int i = 0; i < defaultTextures.Count; ++i)
if (defaultTextures != null)
{
if (defaultTextures.TryGetValue(new TextureArrayKey(textureID, resolution, i), out var defaultTexture))
for (int i = 0; i < defaultTextures.Count; ++i)
{
var defaultSlot = slotHandler.GetNextFreeSlot();
Graphics.CopyTexture(defaultTexture, srcElement: 0, srcMip: 0, defaultSlot.TextureArray, dstElement: defaultSlot.UsedSlotIndex, dstMip: 0);
if (defaultTextures.TryGetValue(new TextureArrayKey(textureID, resolution, i), out var defaultTexture))
{
var defaultSlot = slotHandler.GetNextFreeSlot();
Graphics.CopyTexture(defaultTexture, srcElement: 0, srcMip: 0, defaultSlot.TextureArray, dstElement: defaultSlot.UsedSlotIndex, dstMip: 0);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
using Cysharp.Threading.Tasks;
using DCL.AvatarRendering.Loading;
using DCL.AvatarRendering.Loading.Systems.Abstract;
using DCL.AvatarRendering.Wearables.Helpers;
using DCL.Diagnostics;
using DCL.WebRequests;
using ECS;
using ECS.StreamableLoading.Cache;
using System;

namespace DCL.AvatarRendering.Emotes.Load
{
Expand All @@ -24,9 +26,13 @@ public LoadOwnedEmotesSystem(
IEmoteStorage emoteStorage
) : base(world, cache, emoteStorage, webRequestController, realmData) { }

protected override async UniTask<IAttachmentLambdaResponse<ILambdaResponseElement<EmoteDTO>>> ParsedResponseAsync(GenericDownloadHandlerUtils.Adapter<GenericGetRequest, GenericGetArguments> adapter) =>
protected override async UniTask<IAttachmentLambdaResponse<ILambdaResponseElement<EmoteDTO>>> ParseResponseAsync(GenericDownloadHandlerUtils.Adapter<GenericGetRequest, GenericGetArguments> adapter) =>
await adapter.CreateFromJson<LambdaOwnedEmoteElementList>(WRJsonParser.Unity);

protected override async UniTask<IBuilderLambdaResponse<IBuilderLambdaResponseElement<EmoteDTO>>> ParseBuilderResponseAsync(GenericDownloadHandlerUtils.Adapter<GenericGetRequest, GenericGetArguments> adapter) =>
throw new NotImplementedException();
// => await adapter.CreateFromJson<WearableDTO.BuilderLambdaResponse>(WRJsonParser.Newtonsoft); // TODO: Adapt for 'EmoteDTO'

protected override EmotesResolution AssetFromPreparedIntention(in GetOwnedEmotesFromRealmIntention intention) =>
new (intention.Result, intention.TotalAmount);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"GUID:286980af24684da6acc1caa413039811",
"GUID:3c7b57a14671040bd8c549056adc04f5",
"GUID:56e8195b069a4dca9c4c4f313c65f526",
"GUID:b46779583a009f04ba9f5f31d0e7e6ac"],
"GUID:b46779583a009f04ba9f5f31d0e7e6ac",
"GUID:5ab29fa8ae5769b49ab29e390caca7a4"],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#nullable disable

using System;
using System;
using System.Collections.Generic;

namespace DCL.AvatarRendering.Loading.DTO
{
Expand All @@ -22,6 +21,7 @@ public abstract class AvatarAttachmentDTO
public long timestamp;
public string version;
public Content[] content;
public string? FilesDownloadUrl;

public abstract MetadataBase Metadata { get; }

Expand Down Expand Up @@ -50,6 +50,9 @@ public abstract class MetadataBase
{
public abstract DataBase AbstractData { get; }

// Needed for builder-fetched assets
// public Dictionary<string, string> contents;

//urn
public string id;
public string name;
Expand All @@ -62,7 +65,7 @@ public abstract class MetadataBase
}

[Serializable]
public abstract class DataBase
public class DataBase
{
public Representation[] representations;
public string category;
Expand Down
13 changes: 13 additions & 0 deletions Explorer/Assets/DCL/AvatarRendering/Loading/ILambdaResponse.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using DCL.AvatarRendering.Loading.DTO;
using System.Collections.Generic;

namespace DCL.AvatarRendering.Loading
Expand All @@ -21,4 +22,16 @@ public interface ILambdaResponseElement<out TElementDTO>

IReadOnlyList<ElementIndividualDataDto> IndividualData { get; }
}

public interface IBuilderLambdaResponse<out TBuilderLambdaResponseElement>
{
IReadOnlyList<TBuilderLambdaResponseElement> WearablesCollection { get; }
}

public interface IBuilderLambdaResponseElement<out TElementDTO>
{
IReadOnlyDictionary<string, string> Contents { get; }

TElementDTO BuildWearableDTO();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,42 @@ protected sealed override async UniTask<StreamableLoadingResult<TAsset>> FlowInt
{
await realmData.WaitConfiguredAsync();

var lambdaResponse =
await ParsedResponseAsync(
webRequestController.GetAsync(
new CommonArguments(
BuildUrlFromIntention(in intention),
attemptsCount: intention.CommonArguments.Attempts
),
ct,
GetReportCategory()
)
);

await using (await ExecuteOnThreadPoolScope.NewScopeWithReturnOnMainThreadAsync())
Load(ref intention, lambdaResponse);
URLAddress url = BuildUrlFromIntention(in intention);

if (intention.CommonArguments.NeedsBuilderAPISigning)
{
var lambdaResponse =
await ParseBuilderResponseAsync(
webRequestController.SignedFetchGetAsync(
new CommonArguments(
url,
attemptsCount: intention.CommonArguments.Attempts
),
string.Empty,
ct
)
);

await using (await ExecuteOnThreadPoolScope.NewScopeWithReturnOnMainThreadAsync())
LoadBuilderItem(ref intention, lambdaResponse);
}
else
{
var lambdaResponse =
await ParseResponseAsync(
webRequestController.GetAsync(
new CommonArguments(
url,
attemptsCount: intention.CommonArguments.Attempts
),
ct,
GetReportCategory()
)
);

await using (await ExecuteOnThreadPoolScope.NewScopeWithReturnOnMainThreadAsync())
Load(ref intention, lambdaResponse);
}

return new StreamableLoadingResult<TAsset>(AssetFromPreparedIntention(in intention));
}
Expand Down Expand Up @@ -95,7 +117,21 @@ private void Load<TResponseElement>(ref TIntention intention, IAttachmentLambdaR
}
}

protected abstract UniTask<IAttachmentLambdaResponse<ILambdaResponseElement<TAvatarElementDTO>>> ParsedResponseAsync(GenericDownloadHandlerUtils.Adapter<GenericGetRequest, GenericGetArguments> adapter);
// private void LoadBuilderItem<TResponseElement>(ref TIntention intention, IBuilderLambdaResponse<TResponseElement> lambdaResponse) where TResponseElement : IBuilderLambdaResponseElement<TAvatarElementDTO>
private void LoadBuilderItem(ref TIntention intention, IBuilderLambdaResponse<IBuilderLambdaResponseElement<TAvatarElementDTO>> lambdaResponse)
{
intention.SetTotal(lambdaResponse.WearablesCollection.Count);

foreach (var element in lambdaResponse.WearablesCollection)
{
var wearable = avatarElementStorage.GetOrAddByDTO(element.BuildWearableDTO());
intention.AppendToResult(wearable);
}
}

protected abstract UniTask<IAttachmentLambdaResponse<ILambdaResponseElement<TAvatarElementDTO>>> ParseResponseAsync(GenericDownloadHandlerUtils.Adapter<GenericGetRequest, GenericGetArguments> adapter);

protected abstract UniTask<IBuilderLambdaResponse<IBuilderLambdaResponseElement<TAvatarElementDTO>>> ParseBuilderResponseAsync(GenericDownloadHandlerUtils.Adapter<GenericGetRequest, GenericGetArguments> adapter);

protected abstract TAsset AssetFromPreparedIntention(in TIntention intention);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
using ECS.TestSuite;
using NUnit.Framework;
using System.Collections.Generic;
using Promise = ECS.StreamableLoading.Common.AssetPromise<UnityEngine.Texture2D, ECS.StreamableLoading.Textures.GetTextureIntention>;
using Promise = ECS.StreamableLoading.Common.AssetPromise<ECS.StreamableLoading.Textures.Texture2DData, ECS.StreamableLoading.Textures.GetTextureIntention>;

namespace DCL.AvatarRendering.Wearables.Tests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
using System.Threading;
using UnityEngine;
using Utility;
using Promise = ECS.StreamableLoading.Common.AssetPromise<UnityEngine.Texture2D, ECS.StreamableLoading.Textures.GetTextureIntention>;
using Promise = ECS.StreamableLoading.Common.AssetPromise<ECS.StreamableLoading.Textures.Texture2DData, ECS.StreamableLoading.Textures.GetTextureIntention>;
using AssetBundlePromise = ECS.StreamableLoading.Common.AssetPromise<ECS.StreamableLoading.AssetBundles.AssetBundleData, ECS.StreamableLoading.AssetBundles.GetAssetBundleIntention>;

namespace DCL.AvatarRendering.Thumbnails.Utils
Expand Down Expand Up @@ -78,7 +78,8 @@ private static void CreateWearableThumbnailTexturePromise(
using var urlBuilderScope = URL_BUILDER_POOL.AutoScope();
var urlBuilder = urlBuilderScope.Value;
urlBuilder.Clear();
urlBuilder.AppendDomain(realmData.Ipfs.ContentBaseUrl).AppendPath(thumbnailPath);
urlBuilder.AppendDomain(attachment.DTO.FilesDownloadUrl != null ? URLDomain.FromString(attachment.DTO.FilesDownloadUrl) : realmData.Ipfs.ContentBaseUrl)
.AppendPath(thumbnailPath);

var promise = Promise.Create(world,
new GetTextureIntention
Expand Down
Loading
Loading