Refactor VRCBoard components to replace material override with material index and update related methods

This commit is contained in:
2024-10-18 13:51:27 +03:00
parent 5d0d1b8f37
commit 9777e0225d
4 changed files with 61 additions and 32 deletions

View File

@@ -311,12 +311,13 @@ namespace VRCBoard
}
atlasIndex = (int)atlasIndexToken.Double;
texture = _downloadedAtlasTextures[atlasIndex];
bool positionSuccess = uploadInfo.TryGetValue("p", out DataToken positionToken);
if (!positionSuccess || positionToken.TokenType != TokenType.Double)
{
return false;
}
texture = _downloadedAtlasTextures[atlasIndex];
position = (int)positionToken.Double;
return true;
}
@@ -517,27 +518,28 @@ namespace VRCBoard
_atlasDownloadTimes[index] = Time.time;
Debug.Log("Downloaded atlas texture " + index);
foreach (var component in vrcBoardComponents)
component._OnImageLoaded(index);
component._OnAtlasImageLoaded(index);
}
[PublicAPI]
public Texture2D GetTexture2D(string uploader, string imageId)
{
bool success = _GetImageAtlasTexture(imageId, uploader, out int atlasIndex, out Texture2D texture,
out int position, out int size, out string type);
if (!success)
if (!success || atlasIndex == -1)
{
Debug.LogWarning("[VRCBoard] [GetTexture2D] Failed to get texture for " + uploader);
return null;
}
if (!texture)
if (texture == null)
{
Debug.LogWarning("[VRCBoard] [GetTexture2D] Failed to get texture for " + uploader);
return null;
}
int blockSize = (int)Mathf.Floor((float)texture.width / (float)size);
int blockSize = (int)Mathf.Floor((float)(texture.width+1) / (float)(size));
int startX = position % size;
@@ -552,6 +554,9 @@ namespace VRCBoard
Color[] pixels = texture.GetPixels(startX * blockWidth, startY * blockHeight, blockWidth, blockHeight);
newTexture.SetPixels(pixels);
newTexture.wrapMode = TextureWrapMode.Clamp;
newTexture.filterMode = FilterMode.Trilinear;
newTexture.anisoLevel = 1;
//newTexture.alphaIsTransparency = true;
newTexture.Apply();
return newTexture;
}