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

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