//クソ雑魚AddComponent
    public void VrmLipSyncSetup()
    {
        //LipSyncTargetNameでVRMを検索、Proxyを取得できなければセットアップの終了
        VrmAvatar = GameObject.Find(LipSyncTargetName);
        VrmProxy  = GetVrmProxy(VrmAvatar);
        if (VrmProxy == null)
        {
            return;
        }

        if (VrmAvatar.GetComponent <AudioSource>() == null)
        {
            VrmAvatar.AddComponent <AudioSource>();
        }

        if (VrmAvatar.GetComponent <OVRLipSyncMicInput>() == null)
        {
            VrmAvatar.AddComponent <OVRLipSyncMicInput>();
        }

        if (VrmAvatar.GetComponent <OVRLipSyncContext>() == null)
        {
            VrmAvatar.AddComponent <OVRLipSyncContext>();
        }

        if (VrmAvatar.GetComponent <OVRLipSyncContextMorphTarget>() == null)
        {
            VrmAvatar.AddComponent <OVRLipSyncContextMorphTarget>();
        }

        morphTarget = VrmAvatar.GetComponent <OVRLipSyncContextMorphTarget>();
        Debug.Log("VrmAvatarにLipSyncをセットアップしました。");
    }
Exemplo n.º 2
0
    /// <summary>
    /// Sets the active GameObject
    /// </summary>
    /// <returns><c>true</c>, if active was set, <c>false</c> otherwise.</returns>
    /// <param name="target">Target.</param>
    public bool SetActive <T>(int target) where T : MonoBehaviour
    {
        if ((target < 0) || (target >= SwitchTargets.Length))
        {
            return(false);
        }

        for (int i = 0; i < SwitchTargets.Length; i++)
        {
            SwitchTargets[i].SetActive(false);

            // Disable texture flip or morph target
            OVRLipSyncContextMorphTarget lipsyncContextMorph =
                SwitchTargets[i].GetComponent <OVRLipSyncContextMorphTarget>();
            if (lipsyncContextMorph)
            {
                lipsyncContextMorph.enabled = false;
            }
            OVRLipSyncContextTextureFlip lipsyncContextTexture =
                SwitchTargets[i].GetComponent <OVRLipSyncContextTextureFlip>();
            if (lipsyncContextTexture)
            {
                lipsyncContextTexture.enabled = false;
            }
        }

        SwitchTargets[target].SetActive(true);
        MonoBehaviour lipsyncContext = SwitchTargets[target].GetComponent <T>();

        if (lipsyncContext != null)
        {
            lipsyncContext.enabled = true;
        }

        return(true);
    }
Exemplo n.º 3
0
    private void FinishAvatar()
    {
        GameObject          avatar = playerObj.transform.Find("Avatar").gameObject;
        GameObject          head   = avatar.transform.Find("HeadObject").gameObject;
        SkinnedMeshRenderer skinnedMeshRenderer = head.GetComponent <SkinnedMeshRenderer>();

        // Add audio source to player for speaking sound
        AudioSource audioSource = avatar.AddComponent <AudioSource>();

        OVRLipSyncContext ovrContext = avatar.AddComponent <OVRLipSyncContext>();

        ovrContext.audioSource = audioSource;
        ovrContext.audioMute   = false;

        OVRLipSyncContextMorphTarget ovrMorphTarget = avatar.AddComponent <OVRLipSyncContextMorphTarget>();

        ovrMorphTarget.skinnedMeshRenderer = skinnedMeshRenderer;

        ovrMorphTarget.VisemeToBlendTargets[0]  = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("sil");
        ovrMorphTarget.VisemeToBlendTargets[1]  = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("pp");
        ovrMorphTarget.VisemeToBlendTargets[2]  = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("ff");
        ovrMorphTarget.VisemeToBlendTargets[3]  = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("TH");
        ovrMorphTarget.VisemeToBlendTargets[4]  = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("dd");
        ovrMorphTarget.VisemeToBlendTargets[5]  = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("kk");
        ovrMorphTarget.VisemeToBlendTargets[6]  = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("CH");
        ovrMorphTarget.VisemeToBlendTargets[7]  = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("ss");
        ovrMorphTarget.VisemeToBlendTargets[8]  = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("nn");
        ovrMorphTarget.VisemeToBlendTargets[9]  = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("rr");
        ovrMorphTarget.VisemeToBlendTargets[10] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("AA");
        ovrMorphTarget.VisemeToBlendTargets[11] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("EE");
        ovrMorphTarget.VisemeToBlendTargets[12] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("IH");
        ovrMorphTarget.VisemeToBlendTargets[13] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("OH");
        ovrMorphTarget.VisemeToBlendTargets[14] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("OU");

        ovrMorphTarget.KeySendVisemeSignal     = new int[15];
        ovrMorphTarget.KeySendVisemeSignal[0]  = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("sil");
        ovrMorphTarget.KeySendVisemeSignal[1]  = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("pp");
        ovrMorphTarget.KeySendVisemeSignal[2]  = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("ff");
        ovrMorphTarget.KeySendVisemeSignal[3]  = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("TH");
        ovrMorphTarget.KeySendVisemeSignal[4]  = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("dd");
        ovrMorphTarget.KeySendVisemeSignal[5]  = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("kk");
        ovrMorphTarget.KeySendVisemeSignal[6]  = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("CH");
        ovrMorphTarget.KeySendVisemeSignal[7]  = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("ss");
        ovrMorphTarget.KeySendVisemeSignal[8]  = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("nn");
        ovrMorphTarget.KeySendVisemeSignal[9]  = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("rr");
        ovrMorphTarget.KeySendVisemeSignal[10] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("AA");
        ovrMorphTarget.KeySendVisemeSignal[11] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("EE");
        ovrMorphTarget.KeySendVisemeSignal[12] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("IH");
        ovrMorphTarget.KeySendVisemeSignal[13] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("OH");
        ovrMorphTarget.KeySendVisemeSignal[14] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("OU");

        ovrMorphTarget.SmoothAmount = 10;

        ovrContext.enabled = false;
        ovrContext.enabled = true;

        EyeController eyeController = avatar.AddComponent <EyeController>();

        eyeController.head          = avatar.transform.Find("HeadObject").gameObject;
        eyeController.positiveXAxis = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("EyesRight");
        eyeController.positiveYAxis = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("EyesUp");
        eyeController.negativeXAxis = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("EyesLeft");
        eyeController.negativeYAxis = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("EyesDown");

        eyeController.blinkL = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("EyeBlink_L");
        eyeController.blinkR = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("EyeBlink_R");

        // Set camera
        if (cameraObj != null)
        {
            eyeController.target = cameraObj.transform;
            cameraObj.GetComponent <CameraScript>().target = playerObj.transform;
        }

        // send finish command
        AppSocket.SendCommand(AppSocket.SendType.AVATAR_FINISH);
    }