private void ConfigureHelpers() { Transform head = transform.Find("body/body_renderPart_0/root_JNT/body_JNT/chest_JNT/neckBase_JNT/neck_JNT/head_JNT"); if (head == null) { AvatarLogger.LogError("Avatar helper config failed. Cannot find head transform. All helpers spawning on root avatar transform"); head = transform; } if (MouthAnchor == null) { MouthAnchor = CreateHelperObject(head, MOUTH_HEAD_OFFSET, MOUTH_HELPER_NAME); } if (GetComponent <OvrAvatarLocalDriver>() != null) { if (audioSource == null) { audioSource = MouthAnchor.gameObject.AddComponent <AudioSource>(); } spatializedSource = MouthAnchor.GetComponent <ONSPAudioSource>(); if (spatializedSource == null) { spatializedSource = MouthAnchor.gameObject.AddComponent <ONSPAudioSource>(); } spatializedSource.UseInvSqr = true; spatializedSource.EnableRfl = false; spatializedSource.EnableSpatialization = true; spatializedSource.Far = 100f; spatializedSource.Near = 0.1f; // Add phoneme context to the mouth anchor lipsyncContext = MouthAnchor.GetComponent <OVRLipSyncContext>(); if (lipsyncContext == null) { lipsyncContext = MouthAnchor.gameObject.AddComponent <OVRLipSyncContext>(); } lipsyncContext.provider = EnableLaughter ? OVRLipSync.ContextProviders.Enhanced_with_Laughter : OVRLipSync.ContextProviders.Enhanced; // Ignore audio callback if microphone is owned by VoIP lipsyncContext.skipAudioSource = !CanOwnMicrophone; StartCoroutine(WaitForMouthAudioSource()); } if (GetComponent <OvrAvatarRemoteDriver>() != null) { GazeTarget headTarget = head.gameObject.AddComponent <GazeTarget>(); headTarget.Type = ovrAvatarGazeTargetType.AvatarHead; AvatarLogger.Log("Added head as gaze target"); Transform hand = transform.Find("hand_left"); if (hand == null) { AvatarLogger.LogWarning("Gaze target helper config failed: Cannot find left hand transform"); } else { GazeTarget handTarget = hand.gameObject.AddComponent <GazeTarget>(); handTarget.Type = ovrAvatarGazeTargetType.AvatarHand; AvatarLogger.Log("Added left hand as gaze target"); } hand = transform.Find("hand_right"); if (hand == null) { AvatarLogger.Log("Gaze target helper config failed: Cannot find right hand transform"); } else { GazeTarget handTarget = hand.gameObject.AddComponent <GazeTarget>(); handTarget.Type = ovrAvatarGazeTargetType.AvatarHand; AvatarLogger.Log("Added right hand as gaze target"); } } }
void Start() { if (OvrAvatarSDKManager.Instance == null) { return; } #if !UNITY_ANDROID if (CombineMeshes) { CombineMeshes = false; AvatarLogger.Log("Combined Meshes currently only supported on mobile"); } #endif #if !UNITY_5_5_OR_NEWER if (CombineMeshes) { CombineMeshes = false; AvatarLogger.LogWarning("Combined Meshes requires Unity 5.5.0+"); } #endif materialManager = gameObject.AddComponent <OvrAvatarMaterialManager>(); try { oculusUserIDInternal = UInt64.Parse(oculusUserID); } catch (Exception) { oculusUserIDInternal = 0; AvatarLogger.LogWarning("Invalid Oculus User ID Format"); } // If no oculus ID is supplied then turn off combine meshes to prevent the texture arrays // being populated by invalid textures. if (oculusUserIDInternal == 0) { AvatarLogger.LogWarning("Oculus User ID set to 0. Provide actual user ID: " + gameObject.name); CombineMeshes = false; } AvatarLogger.Log("Starting OvrAvatar " + gameObject.name); AvatarLogger.Log(AvatarLogger.Tab + "LOD: " + LevelOfDetail.ToString()); AvatarLogger.Log(AvatarLogger.Tab + "Combine Meshes: " + CombineMeshes); AvatarLogger.Log(AvatarLogger.Tab + "Force Mobile Textures: " + USE_MOBILE_TEXTURE_FORMAT); AvatarLogger.Log(AvatarLogger.Tab + "Oculus User ID: " + oculusUserIDInternal); Capabilities = 0; bool is3Dof = false; var headsetType = OVRPlugin.GetSystemHeadsetType(); switch (headsetType) { case OVRPlugin.SystemHeadset.GearVR_R320: case OVRPlugin.SystemHeadset.GearVR_R321: case OVRPlugin.SystemHeadset.GearVR_R322: case OVRPlugin.SystemHeadset.GearVR_R323: case OVRPlugin.SystemHeadset.GearVR_R324: case OVRPlugin.SystemHeadset.GearVR_R325: case OVRPlugin.SystemHeadset.Oculus_Go: is3Dof = true; break; case OVRPlugin.SystemHeadset.Oculus_Quest: case OVRPlugin.SystemHeadset.Rift_S: case OVRPlugin.SystemHeadset.Rift_DK1: case OVRPlugin.SystemHeadset.Rift_DK2: case OVRPlugin.SystemHeadset.Rift_CV1: default: break; } // The SDK 3 DOF Arm Model requires the body skeleton to pose itself. It will crash without it // The likely use case here is trying to have an invisible body. // T45010595 if (is3Dof && !EnableBody) { AvatarLogger.Log("Forcing the Body component for 3Dof hand tracking, and setting the visibility to 1st person"); EnableBody = true; ShowFirstPerson = true; ShowThirdPerson = false; } if (EnableBody) { Capabilities |= ovrAvatarCapabilities.Body; } if (EnableHands) { Capabilities |= ovrAvatarCapabilities.Hands; } if (EnableBase && EnableBody) { Capabilities |= ovrAvatarCapabilities.Base; } if (EnableExpressive) { Capabilities |= ovrAvatarCapabilities.Expressive; } // Enable body tilt on 6dof devices if (OVRPlugin.positionSupported) { Capabilities |= ovrAvatarCapabilities.BodyTilt; } ShowLeftController(StartWithControllers); ShowRightController(StartWithControllers); OvrAvatarSDKManager.AvatarSpecRequestParams avatarSpecRequest = new OvrAvatarSDKManager.AvatarSpecRequestParams( oculusUserIDInternal, this.AvatarSpecificationCallback, CombineMeshes, LevelOfDetail, USE_MOBILE_TEXTURE_FORMAT, LookAndFeelVersion, FallbackLookAndFeelVersion, EnableExpressive); OvrAvatarSDKManager.Instance.RequestAvatarSpecification(avatarSpecRequest); OvrAvatarSDKManager.Instance.AddLoadingAvatar(GetInstanceID()); waitingForCombinedMesh = CombineMeshes; if (Driver != null) { Driver.Mode = UseSDKPackets ? OvrAvatarDriver.PacketMode.SDK : OvrAvatarDriver.PacketMode.Unity; } }
void Update() { if (Instance == null) { return; } #if AVATAR_DEBUG // Call before ovrAvatarMessage_Pop which flushes the state CAPI.ovrAvatar_DrawDebugLines(); #endif // Dispatch waiting avatar spec request if (avatarSpecificationQueue.Count > 0 && (avatarSpecRequestAvailable || Time.time - lastDispatchedAvatarSpecRequestTime >= AVATAR_SPEC_REQUEST_TIMEOUT)) { avatarSpecRequestAvailable = false; AvatarSpecRequestParams avatarSpec = avatarSpecificationQueue.Dequeue(); DispatchAvatarSpecificationRequest(avatarSpec); lastDispatchedAvatarSpecRequestTime = Time.time; AvatarLogger.Log("Avatar spec request dispatched: " + avatarSpec._userId); } IntPtr message = CAPI.ovrAvatarMessage_Pop(); if (message == IntPtr.Zero) { return; } ovrAvatarMessageType messageType = CAPI.ovrAvatarMessage_GetType(message); switch (messageType) { case ovrAvatarMessageType.AssetLoaded: { ovrAvatarMessage_AssetLoaded assetMessage = CAPI.ovrAvatarMessage_GetAssetLoaded(message); IntPtr asset = assetMessage.asset; UInt64 assetID = assetMessage.assetID; ovrAvatarAssetType assetType = CAPI.ovrAvatarAsset_GetType(asset); OvrAvatarAsset assetData = null; IntPtr avatarOwner = IntPtr.Zero; switch (assetType) { case ovrAvatarAssetType.Mesh: assetData = new OvrAvatarAssetMesh(assetID, asset, ovrAvatarAssetType.Mesh); break; case ovrAvatarAssetType.Texture: assetData = new OvrAvatarAssetTexture(assetID, asset); break; case ovrAvatarAssetType.Material: assetData = new OvrAvatarAssetMaterial(assetID, asset); break; case ovrAvatarAssetType.CombinedMesh: avatarOwner = CAPI.ovrAvatarAsset_GetAvatar(asset); assetData = new OvrAvatarAssetMesh(assetID, asset, ovrAvatarAssetType.CombinedMesh); break; case ovrAvatarAssetType.FailedLoad: AvatarLogger.LogWarning("Asset failed to load from SDK " + assetID); break; default: throw new NotImplementedException(string.Format("Unsupported asset type format {0}", assetType.ToString())); } HashSet <assetLoadedCallback> callbackSet; if (assetType == ovrAvatarAssetType.CombinedMesh) { if (!assetCache.ContainsKey(assetID)) { assetCache.Add(assetID, assetData); } combinedMeshLoadedCallback callback; if (combinedMeshLoadedCallbacks.TryGetValue(avatarOwner, out callback)) { callback(asset); combinedMeshLoadedCallbacks.Remove(avatarOwner); } else { AvatarLogger.LogWarning("Loaded a combined mesh with no owner: " + assetMessage.assetID); } } else { if (assetData != null && assetLoadedCallbacks.TryGetValue(assetMessage.assetID, out callbackSet)) { assetCache.Add(assetID, assetData); foreach (var callback in callbackSet) { callback(assetData); } assetLoadedCallbacks.Remove(assetMessage.assetID); } } break; } case ovrAvatarMessageType.AvatarSpecification: { avatarSpecRequestAvailable = true; ovrAvatarMessage_AvatarSpecification spec = CAPI.ovrAvatarMessage_GetAvatarSpecification(message); HashSet <specificationCallback> callbackSet; if (specificationCallbacks.TryGetValue(spec.oculusUserID, out callbackSet)) { foreach (var callback in callbackSet) { callback(spec.avatarSpec); } specificationCallbacks.Remove(spec.oculusUserID); } else { AvatarLogger.LogWarning("Error, got an avatar specification callback from a user id we don't have a record for: " + spec.oculusUserID); } break; } default: throw new NotImplementedException("Unhandled ovrAvatarMessageType: " + messageType); } CAPI.ovrAvatarMessage_Free(message); }
void Start() { if (OvrAvatarSDKManager.Instance == null) { return; } #if !UNITY_ANDROID if (CombineMeshes) { CombineMeshes = false; AvatarLogger.Log("Combined Meshes currently only supported on mobile"); } #endif #if !UNITY_5_5_OR_NEWER if (CombineMeshes) { CombineMeshes = false; AvatarLogger.LogWarning("Combined Meshes requires Unity 5.5.0+"); } #endif materialManager = gameObject.AddComponent <OvrAvatarMaterialManager>(); try { oculusUserIDInternal = UInt64.Parse(oculusUserID); } catch (Exception) { oculusUserIDInternal = 0; AvatarLogger.LogWarning("Invalid Oculus User ID Format"); } // If no oculus ID is supplied then turn off combine meshes to prevent the texture arrays // being populated by invalid textures. if (oculusUserIDInternal == 0) { AvatarLogger.LogWarning("Oculus User ID set to 0. Provide actual user ID: " + gameObject.name); CombineMeshes = false; } AvatarLogger.Log("Starting OvrAvatar " + gameObject.name); AvatarLogger.Log(AvatarLogger.Tab + "LOD: " + LevelOfDetail.ToString()); AvatarLogger.Log(AvatarLogger.Tab + "Combine Meshes: " + CombineMeshes); AvatarLogger.Log(AvatarLogger.Tab + "Force Mobile Textures: " + USE_MOBILE_TEXTURE_FORMAT); AvatarLogger.Log(AvatarLogger.Tab + "Oculus User ID: " + oculusUserIDInternal); Capabilities = 0; if (EnableBody) { Capabilities |= ovrAvatarCapabilities.Body; } if (EnableHands) { Capabilities |= ovrAvatarCapabilities.Hands; } if (EnableBase && EnableBody) { Capabilities |= ovrAvatarCapabilities.Base; } if (EnableExpressive) { Capabilities |= ovrAvatarCapabilities.Expressive; } // Enable body tilt on 6dof devices if (OVRPlugin.positionSupported) { Capabilities |= ovrAvatarCapabilities.BodyTilt; } ShowLeftController(StartWithControllers); ShowRightController(StartWithControllers); OvrAvatarSDKManager.AvatarSpecRequestParams avatarSpecRequest = new OvrAvatarSDKManager.AvatarSpecRequestParams( oculusUserIDInternal, this.AvatarSpecificationCallback, CombineMeshes, LevelOfDetail, USE_MOBILE_TEXTURE_FORMAT, LookAndFeelVersion, FallbackLookAndFeelVersion, EnableExpressive); OvrAvatarSDKManager.Instance.RequestAvatarSpecification(avatarSpecRequest); OvrAvatarSDKManager.Instance.AddLoadingAvatar(GetInstanceID()); waitingForCombinedMesh = CombineMeshes; if (Driver != null) { Driver.Mode = UseSDKPackets ? OvrAvatarDriver.PacketMode.SDK : OvrAvatarDriver.PacketMode.Unity; } }
void Start() { #if !UNITY_ANDROID if (CombineMeshes) { CombineMeshes = false; AvatarLogger.Log("Combine Meshes Currently Only Supported On Android"); } #endif #if !UNITY_5_5_OR_NEWER if (CombineMeshes) { CombineMeshes = false; AvatarLogger.LogWarning("Unity Version too old to use Combined Mesh Shader, required 5.5.0+"); } #endif try { oculusUserIDInternal = UInt64.Parse(oculusUserID); } catch (Exception) { oculusUserIDInternal = 0; AvatarLogger.LogWarning("Invalid Oculus User ID Format"); } AvatarLogger.Log("Starting OvrAvatar " + gameObject.name); AvatarLogger.Log(AvatarLogger.Tab + "LOD: " + LevelOfDetail.ToString()); AvatarLogger.Log(AvatarLogger.Tab + "Combine Meshes: " + CombineMeshes); AvatarLogger.Log(AvatarLogger.Tab + "Force Mobile Textures: " + ForceMobileTextureFormat); AvatarLogger.Log(AvatarLogger.Tab + "Oculus User ID: " + oculusUserIDInternal); Capabilities = 0; if (EnableBody) { Capabilities |= ovrAvatarCapabilities.Body; } if (EnableHands) { Capabilities |= ovrAvatarCapabilities.Hands; } if (EnableBase && EnableBody) { Capabilities |= ovrAvatarCapabilities.Base; } if (EnableExpressive) { Capabilities |= ovrAvatarCapabilities.Expressive; } #if !UNITY_ANDROID Capabilities |= ovrAvatarCapabilities.BodyTilt; #endif ShowLeftController(StartWithControllers); ShowRightController(StartWithControllers); OvrAvatarSDKManager.Instance.RequestAvatarSpecification( oculusUserIDInternal, this.AvatarSpecificationCallback, CombineMeshes, LevelOfDetail, ForceMobileTextureFormat, LookAndFeelVersion, FallbackLookAndFeelVersion, EnableExpressive); WaitingForCombinedMesh = CombineMeshes; if (Driver != null) { Driver.Mode = UseSDKPackets ? OvrAvatarDriver.PacketMode.SDK : OvrAvatarDriver.PacketMode.Unity; } }
// Update is called once per frame void Update() { IntPtr message = CAPI.ovrAvatarMessage_Pop(); if (message == IntPtr.Zero) { return; } ovrAvatarMessageType messageType = CAPI.ovrAvatarMessage_GetType(message); switch (messageType) { case ovrAvatarMessageType.AssetLoaded: { ovrAvatarMessage_AssetLoaded assetMessage = CAPI.ovrAvatarMessage_GetAssetLoaded(message); IntPtr asset = assetMessage.asset; UInt64 assetID = assetMessage.assetID; ovrAvatarAssetType assetType = CAPI.ovrAvatarAsset_GetType(asset); OvrAvatarAsset assetData; IntPtr avatarOwner = IntPtr.Zero; switch (assetType) { case ovrAvatarAssetType.Mesh: assetData = new OvrAvatarAssetMesh(assetID, asset, ovrAvatarAssetType.Mesh); break; case ovrAvatarAssetType.Texture: assetData = new OvrAvatarAssetTexture(assetID, asset); break; case ovrAvatarAssetType.Material: assetData = new OvrAvatarAssetMaterial(assetID, asset); break; case ovrAvatarAssetType.CombinedMesh: avatarOwner = CAPI.ovrAvatarAsset_GetAvatar(asset); assetData = new OvrAvatarAssetMesh(assetID, asset, ovrAvatarAssetType.CombinedMesh); break; default: throw new NotImplementedException(string.Format("Unsupported asset type format {0}", assetType.ToString())); } HashSet <assetLoadedCallback> callbackSet; if (assetType == ovrAvatarAssetType.CombinedMesh) { if (!assetCache.ContainsKey(assetID)) { assetCache.Add(assetID, assetData); } combinedMeshLoadedCallback callback; if (combinedMeshLoadedCallbacks.TryGetValue(avatarOwner, out callback)) { callback(asset); combinedMeshLoadedCallbacks.Remove(avatarOwner); } else { AvatarLogger.LogWarning("Loaded a combined mesh with no owner: " + assetMessage.assetID); } } else { if (assetLoadedCallbacks.TryGetValue(assetMessage.assetID, out callbackSet)) { assetCache.Add(assetID, assetData); foreach (var callback in callbackSet) { callback(assetData); } assetLoadedCallbacks.Remove(assetMessage.assetID); } } break; } case ovrAvatarMessageType.AvatarSpecification: { ovrAvatarMessage_AvatarSpecification spec = CAPI.ovrAvatarMessage_GetAvatarSpecification(message); HashSet <specificationCallback> callbackSet; if (specificationCallbacks.TryGetValue(spec.oculusUserID, out callbackSet)) { foreach (var callback in callbackSet) { callback(spec.avatarSpec); } specificationCallbacks.Remove(spec.oculusUserID); } else { AvatarLogger.LogWarning("Error, got an avatar specification callback from a user id we don't have a record for: " + spec.oculusUserID); } break; } default: throw new NotImplementedException("Unhandled ovrAvatarMessageType: " + messageType); } CAPI.ovrAvatarMessage_Free(message); }
private void ConfigureHelpers() { Transform head = transform.Find("body/body_renderPart_0/root_JNT/body_JNT/chest_JNT/neckBase_JNT/neck_JNT/head_JNT"); if (head == null) { AvatarLogger.LogError("Avatar helper config failed. Cannot find head transform. All helpers spawning on root avatar transform"); head = transform; } if (MouthAnchor == null) { MouthAnchor = CreateHelperObject(head, MOUTH_HEAD_OFFSET, MOUTH_HELPER_NAME); } if (GetComponent <OvrAvatarLocalDriver>() != null) { if (audioSource == null) { audioSource = MouthAnchor.gameObject.AddComponent <AudioSource>(); } spatializedSource = MouthAnchor.GetComponent <ONSPAudioSource>(); if (spatializedSource == null) { spatializedSource = MouthAnchor.gameObject.AddComponent <ONSPAudioSource>(); } spatializedSource.UseInvSqr = true; spatializedSource.EnableRfl = false; spatializedSource.EnableSpatialization = true; spatializedSource.Far = 100f; spatializedSource.Near = 0.1f; StartCoroutine(WaitForMouthAudioSource()); } if (GetComponent <OvrAvatarRemoteDriver>() != null) { GazeTarget headTarget = head.gameObject.AddComponent <GazeTarget>(); headTarget.Type = ovrAvatarGazeTargetType.AvatarHead; AvatarLogger.Log("Added head as gaze target"); Transform hand = transform.Find("hand_left"); if (hand == null) { AvatarLogger.LogWarning("Gaze target helper config failed: Cannot find left hand transform"); } else { GazeTarget handTarget = hand.gameObject.AddComponent <GazeTarget>(); handTarget.Type = ovrAvatarGazeTargetType.AvatarHand; AvatarLogger.Log("Added left hand as gaze target"); } hand = transform.Find("hand_right"); if (hand == null) { AvatarLogger.Log("Gaze target helper config failed: Cannot find right hand transform"); } else { GazeTarget handTarget = hand.gameObject.AddComponent <GazeTarget>(); handTarget.Type = ovrAvatarGazeTargetType.AvatarHand; AvatarLogger.Log("Added right hand as gaze target"); } } }