| 1 | using System; |
| 2 | using Oculus.Avatar; |
| 3 | using UnityEngine; |
| 4 | |
| 5 | public class OvrAvatarAssetTexture : OvrAvatarAsset |
| 6 | { |
| 7 | public Texture2D texture; |
| 8 | private const int ASTCHeaderSize = 16; |
| 9 | |
| 10 | public OvrAvatarAssetTexture(UInt64 _assetId, IntPtr asset) { |
| 11 | assetID = _assetId; |
| 12 | ovrAvatarTextureAssetData textureAssetData = CAPI.ovrAvatarAsset_GetTextureData(asset); |
| 13 | TextureFormat format; |
| 14 | IntPtr textureData = textureAssetData.textureData; |
| 15 | int textureDataSize = (int)textureAssetData.textureDataSize; |
| 16 | |
| 17 | AvatarLogger.Log( |
| 18 | "OvrAvatarAssetTexture - " |
| 19 | + _assetId |
| 20 | + ": " |
| 21 | + textureAssetData.format.ToString() |
| 22 | + " " |
| 23 | + textureAssetData.sizeX |
| 24 | + "x" |
| 25 | + textureAssetData.sizeY); |
| 26 | |
| 27 | switch (textureAssetData.format) |
| 28 | { |
| 29 | case ovrAvatarTextureFormat.RGB24: |
| 30 | format = TextureFormat.RGB24; |
| 31 | break; |
| 32 | case ovrAvatarTextureFormat.DXT1: |
| 33 | format = TextureFormat.DXT1; |
| 34 | break; |
| 35 | case ovrAvatarTextureFormat.DXT5: |
| 36 | format = TextureFormat.DXT5; |
| 37 | break; |
| 38 | case ovrAvatarTextureFormat.ASTC_RGB_6x6: |
| 39 | format = TextureFormat.ASTC_RGB_6x6; |
| 40 | textureData = new IntPtr(textureData.ToInt64() + ASTCHeaderSize); |
| 41 | textureDataSize -= ASTCHeaderSize; |
| 42 | break; |
| 43 | case ovrAvatarTextureFormat.ASTC_RGB_6x6_MIPMAPS: |
| 44 | format = TextureFormat.ASTC_RGB_6x6; |
| 45 | break; |
| 46 | default: |
| 47 | throw new NotImplementedException( |
| 48 | string.Format("Unsupported texture format {0}", |
| 49 | textureAssetData.format.ToString())); |
| 50 | } |
| 51 | texture = new Texture2D( |
| 52 | (int)textureAssetData.sizeX, (int)textureAssetData.sizeY, |
| 53 | format, textureAssetData.mipCount > 1, |
| 54 | QualitySettings.activeColorSpace == ColorSpace.Gamma ? false : true) |
| 55 | { |
| 56 | filterMode = FilterMode.Trilinear, |
| 57 | anisoLevel = 4, |
| 58 | }; |
| 59 | texture.LoadRawTextureData(textureData, textureDataSize); |
| 60 | texture.Apply(true, false); |
| 61 | } |
| 62 | } |