public void RefreshBodyParts() { if (Body != null) { OvrAvatarComponent component = Body.GetComponent <OvrAvatarComponent>(); foreach (var part in component.RenderParts) { Destroy(part.gameObject); } component.RenderParts.Clear(); ovrAvatarBodyComponent?sdkBodyComponent = CAPI.ovrAvatarPose_GetBodyComponent(sdkAvatar); if (sdkBodyComponent != null) { ovrAvatarComponent sdKComponent = (ovrAvatarComponent)Marshal.PtrToStructure(sdkBodyComponent.Value.renderComponent, typeof(ovrAvatarComponent)); AddRenderParts(component, sdKComponent, Body.gameObject.transform); } else { throw new Exception("Destroyed the body component, but didn't find a new one in the SDK"); } } }
private void UpdateVoiceBehavior() { if (!EnableMouthVertexAnimation) { return; } if (Body != null) { OvrAvatarComponent component = Body.GetComponent <OvrAvatarComponent>(); VoiceAmplitude = Mathf.Clamp(VoiceAmplitude, 0f, 1f); if (component.RenderParts.Count > 0) { var material = component.RenderParts[0].mesh.sharedMaterial; var neckJoint = component.RenderParts[0].mesh.transform.Find(NECK_JONT); var scaleDiff = neckJoint.TransformPoint(Vector3.up) - neckJoint.position; material.SetFloat(MOUTH_SCALE_PROPERTY, scaleDiff.magnitude); material.SetFloat( VOICE_PROPERTY, Mathf.Min(scaleDiff.magnitude * MOUTH_MAX_GLOBAL, scaleDiff.magnitude * VoiceAmplitude * MOUTH_SCALE_GLOBAL)); material.SetVector( MOUTH_POSITION_PROPERTY, neckJoint.TransformPoint(MOUTH_POSITION_OFFSET)); material.SetVector(MOUTH_DIRECTION_PROPERTY, neckJoint.up); } } }