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.

38 lines
1.6 KiB

  1. using UnityEngine;
  2. using System.Collections;
  3. using System;
  4. using Oculus.Avatar;
  5. public class OvrAvatarSkinnedMeshRenderPBSComponent : OvrAvatarRenderComponent {
  6. bool isMaterialInitilized = false;
  7. internal void Initialize(ovrAvatarRenderPart_SkinnedMeshRenderPBS skinnedMeshRenderPBS, Shader shader, int thirdPersonLayer, int firstPersonLayer)
  8. {
  9. if (shader == null)
  10. {
  11. shader = Shader.Find("OvrAvatar/AvatarSurfaceShaderPBS");
  12. }
  13. mesh = CreateSkinnedMesh(skinnedMeshRenderPBS.meshAssetID, skinnedMeshRenderPBS.visibilityMask, thirdPersonLayer, firstPersonLayer);
  14. mesh.sharedMaterial = CreateAvatarMaterial(gameObject.name + "_material", shader);
  15. bones = mesh.bones;
  16. }
  17. internal void UpdateSkinnedMeshRenderPBS(OvrAvatar avatar, IntPtr renderPart, Material mat)
  18. {
  19. if (!isMaterialInitilized)
  20. {
  21. isMaterialInitilized = true;
  22. UInt64 albedoTextureID = CAPI.ovrAvatarSkinnedMeshRenderPBS_GetAlbedoTextureAssetID(renderPart);
  23. UInt64 surfaceTextureID = CAPI.ovrAvatarSkinnedMeshRenderPBS_GetSurfaceTextureAssetID(renderPart);
  24. mat.SetTexture("_Albedo", OvrAvatarComponent.GetLoadedTexture(albedoTextureID));
  25. mat.SetTexture("_Surface", OvrAvatarComponent.GetLoadedTexture(surfaceTextureID));
  26. }
  27. ovrAvatarVisibilityFlags visibilityMask = CAPI.ovrAvatarSkinnedMeshRenderPBS_GetVisibilityMask(renderPart);
  28. ovrAvatarTransform localTransform = CAPI.ovrAvatarSkinnedMeshRenderPBS_GetTransform(renderPart);
  29. UpdateSkinnedMesh(avatar, bones, localTransform, visibilityMask, renderPart);
  30. }
  31. }