Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

62 lines
2.2 KiB

using System;
using Oculus.Avatar;
using UnityEngine;
public class OvrAvatarAssetTexture : OvrAvatarAsset
{
public Texture2D texture;
private const int ASTCHeaderSize = 16;
public OvrAvatarAssetTexture(UInt64 _assetId, IntPtr asset) {
assetID = _assetId;
ovrAvatarTextureAssetData textureAssetData = CAPI.ovrAvatarAsset_GetTextureData(asset);
TextureFormat format;
IntPtr textureData = textureAssetData.textureData;
int textureDataSize = (int)textureAssetData.textureDataSize;
AvatarLogger.Log(
"OvrAvatarAssetTexture - "
+ _assetId
+ ": "
+ textureAssetData.format.ToString()
+ " "
+ textureAssetData.sizeX
+ "x"
+ textureAssetData.sizeY);
switch (textureAssetData.format)
{
case ovrAvatarTextureFormat.RGB24:
format = TextureFormat.RGB24;
break;
case ovrAvatarTextureFormat.DXT1:
format = TextureFormat.DXT1;
break;
case ovrAvatarTextureFormat.DXT5:
format = TextureFormat.DXT5;
break;
case ovrAvatarTextureFormat.ASTC_RGB_6x6:
format = TextureFormat.ASTC_RGB_6x6;
textureData = new IntPtr(textureData.ToInt64() + ASTCHeaderSize);
textureDataSize -= ASTCHeaderSize;
break;
case ovrAvatarTextureFormat.ASTC_RGB_6x6_MIPMAPS:
format = TextureFormat.ASTC_RGB_6x6;
break;
default:
throw new NotImplementedException(
string.Format("Unsupported texture format {0}",
textureAssetData.format.ToString()));
}
texture = new Texture2D(
(int)textureAssetData.sizeX, (int)textureAssetData.sizeY,
format, textureAssetData.mipCount > 1,
QualitySettings.activeColorSpace == ColorSpace.Gamma ? false : true)
{
filterMode = FilterMode.Trilinear,
anisoLevel = 4,
};
texture.LoadRawTextureData(textureData, textureDataSize);
texture.Apply(true, false);
}
}