OvrAvatarAssetTexture.cs
2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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:
#if UNITY_2020_1_OR_NEWER
format = TextureFormat.ASTC_6x6;
#else
format = TextureFormat.ASTC_RGB_6x6;
#endif
textureData = new IntPtr(textureData.ToInt64() + ASTCHeaderSize);
textureDataSize -= ASTCHeaderSize;
break;
case ovrAvatarTextureFormat.ASTC_RGB_6x6_MIPMAPS:
#if UNITY_2020_1_OR_NEWER
format = TextureFormat.ASTC_6x6;
#else
format = TextureFormat.ASTC_RGB_6x6;
#endif
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);
}
}