Beispiel #1
0
        public void load()
        {
            if (mocFile != null)
            {
                live2DModel = Live2DModelUnity.loadModel(mocFile.bytes);

                for (int i = 0; i < textureFiles.Length; i++)
                {
                    if (textureFiles[i] != null)
                    {
                        live2DModel.setTexture(i, textureFiles[i]);
                    }
                }

                float modelWidth = live2DModel.getCanvasWidth();
                live2DCanvasPos = Matrix4x4.Ortho(0, modelWidth, modelWidth, 0, -50.0f, 50.0f);
            }

            if (physicsFile != null)
            {
                physics = L2DPhysics.load(physicsFile.bytes);
            }

            if (poseFile != null)
            {
                pose = L2DPose.load(poseFile.bytes);
            }
        }
    void Load(byte[] moc, Texture2D[] textures, byte[] pose)
    {
        if (live2DModel != null)
        {
            live2DModel.releaseModel();
        }

        live2DModel = Live2DModelUnity.loadModel(moc);

        for (int i = 0; i < textures.Length; i++)
        {
            live2DModel.setTexture(i, textures[i]);
        }

        float modelWidth = live2DModel.getCanvasWidth();

        live2DCanvasPos = Matrix4x4.Ortho(0, modelWidth, modelWidth, 0, -10.0f, 10.0f);

        if (pose != null)
        {
            live2dPose = L2DPose.load(pose);
        }
        else
        {
            live2dPose = null;
        }
    }
Beispiel #3
0
 public void setPoseFileFromBytes(byte[] bytes)
 {
     if (bytes.Length != 0)
     {
         pose = L2DPose.load(bytes);
     }
 }
Beispiel #4
0
    /**
     * JSONファイルから読み込む
     * 仕様についてはマニュアル参照。JSONスキーマの形式の仕様がある。
     * @param buf
     * @return
     */
    public static L2DPose load(char[] buf)
    {
        L2DPose ret = new L2DPose();

        Value json = Json.parseFromBytes(buf);

        //パーツ切り替え一覧
        List <Value> poseListInfo = json.get("parts_visible").getVector(null);
        int          poseNum      = poseListInfo.Count;

        for (int i_pose = 0; i_pose < poseNum; i_pose++)
        {
            Value poseInfo = poseListInfo[i_pose];

            //IDリストの設定
            List <Value>    idListInfo = poseInfo.get("group").getVector(null);
            int             idNum      = idListInfo.Count;
            L2DPartsParam[] partsGroup = new L2DPartsParam[idNum];
            for (int i_group = 0; i_group < idNum; i_group++)
            {
                Value         partsInfo = idListInfo[i_group];
                L2DPartsParam parts     = new L2DPartsParam(partsInfo.get("id").toString());
                partsGroup[i_group] = parts;

                //リンクするパーツの設定
                if (!partsInfo.getMap(null).ContainsKey("link"))
                {
                    continue;                                                           //リンクが無いときもある
                }
                List <Value> linkListInfo = partsInfo.get("link").getVector(null);
                int          linkNum      = linkListInfo.Count;
                parts.link = new List <L2DPartsParam>();
                for (int i_link = 0; i_link < linkNum; i_link++)
                {
//					string linkID = idListInfo.get(i_group).tostring();//parts ID
                    L2DPartsParam linkParts = new L2DPartsParam(linkListInfo[i_link].toString());
                    parts.link.Add(linkParts);
                }
            }
            ret.addPartsGroup(partsGroup);
        }
        return(ret);
    }
Beispiel #5
0
        /// <summary>
        /// JSON 파일로 간편하게 포즈를 불러옵니다.
        /// </summary>
        /// <param name="path">포즈 구성을 포함한 JSON 파일입니다.</param>
        public static L2DPose LoadPose(string path)
        {
            L2DPose pose       = new L2DPose();
            JObject jsonObject = JObject.Parse(File.ReadAllText(path));

            JToken resultFade;

            jsonObject.TryGetValue("fade_in", out resultFade);
            if (resultFade != null)
            {
                pose.FadeTime = resultFade.Value <int>();
            }

            List <List <L2DParts> > groupList = new List <List <L2DParts> >();

            foreach (JObject json in jsonObject["parts_visible"])
            {
                List <L2DParts> partsList = new List <L2DParts>();
                foreach (JObject group in json["group"])
                {
                    List <L2DParts> linkList = new List <L2DParts>();

                    JToken resultLink;
                    group.TryGetValue("link", out resultLink);
                    if (resultLink != null)
                    {
                        foreach (JValue link in group["link"])
                        {
                            linkList.Add(new L2DParts(link.Value <string>()));
                        }
                    }

                    partsList.Add(new L2DParts(group["id"].Value <string>(), linkList.ToArray()));
                }

                groupList.Add(partsList);
            }
            pose.Groups = groupList.ToArray();

            return(pose);
        }
Beispiel #6
0
 public void loadPose(string fileName)
 {
     if (fileName == null)
     {
         return;
     }
     if (LAppDefine.DEBUG_LOG)
     {
         Debug.Log("Load json : " + fileName);
     }
     try
     {
         TextAsset ta    = (TextAsset)(FileManager.open(fileName) as TextAsset);
         byte[]    bytes = ta.bytes;
         char[]    buf   = System.Text.Encoding.GetEncoding("UTF-8").GetString(bytes).ToCharArray();
         pose = L2DPose.load(buf);
     }
     catch (IOException e)
     {
         Debug.Log(e.StackTrace);
     }
 }
    void Awake()
    {
        chVoice = GetComponent <AudioSource> ();
        //  myRender = gameObject.GetComponentInChildren<MeshRenderer> ();

        lipSyncValue = 0f;

        //초기화 페이즈//


        Live2D.init();

        //json 파일 불러와서 속성 값들 리스트로 뽑아 옴
        model = Live2DModelUnity.loadModel(mocData.bytes);

        //모션 데이터 할당
        motionDataManager = GetComponent <MotionDataManager> ();


        //만약 숨쉬는 모션이 있으면
        if (breathMotion != null)
        {
            breathMotion_ = Live2DMotion.loadMotion(breathMotion.bytes);
        }


        //텍스쳐 세팅
        for (int i = 0; i < textureList.Length; i++)
        {
            model.setTexture(i, textureList [i]);
        }


        // 포즈 파일은 필수적인 것은 아님.
        if (poseData)
        {
            l2dPose = L2DPose.load(poseData.bytes);
        }

        if (physicsData)
        {
            l2dPhysics = L2DPhysics.load(physicsData.bytes);
        }


        //모션을 식별할때 이 스크립트는 string을 사용했지만 enum을 쓰든 뭘 쓰든 모션 식별자로 뭘 써도 무방.



        //아까 초기화한 모델의 가로 사이즈 받아옴.
        var width = model.getCanvasWidth();


        //캔버스 지정
        canvasMatrix = Matrix4x4.Ortho(0.0f, width, width, 0.0f, -50.0f, 50.0f);


        //모션 매니저들 할당. 사실 얘들은 모션들의 우선순위를 정해주는 등의 역할이 있으나 복잡해서 거의 안쓴다.
        //주 역활은 자기가 가지고 있는 주모션 하나를 모델 인스턴스에 적용해주는 것.
        //얘들에게 모션을 주고 여러 설정자들로 모션의 속성들을 설정해줄 수 있다. 그외에 우선순위를 정해주고 등등 기능 있으나 자주 안쓰임.
        //모션 매니저에 현재 모션을 지정해준다고 모델의 모션이 업데이트되지 않는다.
        //반드시 L2D매니저.UpdateParam(모델 인스턴스) 를 호출해줘야 모델 인스턴스의 움직임이 갱신됨.


        l2dMotionManager           = new L2DMotionManager();
        l2dExpressioNMotionManager = new L2DMotionManager();

        //모션 재생 시작


        //모델의 모션 업데이트
        l2dPose.updateParam(model);

        transformCache = transform;
    }
Beispiel #8
0
    /// <summary>
    /// JSONを読み込む
    /// </summary>
    void Json_Read()
    {
        // model.jsonを読み込む
        char[] buf  = modelJson.text.ToCharArray();
        Value  json = Json.parseFromBytes(buf);


        // モデルを読み込む
        mocFile = new TextAsset();
        string live2Dpath = "Live2D/";

        mocFile = (Resources.Load(live2Dpath + json.get("model").toString(), typeof(TextAsset)) as TextAsset);
        Debug.Log(live2Dpath + json.get("model").toString());
        live2DModel = Live2DModelUnity.loadModel(mocFile.bytes);

        // テクスチャを読み込む
        int texture_num = json.get("textures").getVector(null).Count;

        textures = new Texture2D[texture_num];

        for (int i = 0; i < texture_num; i++)
        {
            // 不要な拡張子を削除
            string texturenm = Regex.Replace(json.get("textures").get(i).toString(), ".png$", "");
            textures[i] = (Resources.Load(live2Dpath + texturenm, typeof(Texture2D)) as Texture2D);
            live2DModel.setTexture(i, textures[i]);
        }

        // モーションの配下のキーを取得
        Dictionary <string, Value> motion_keys = json.get("motions").getMap(null);
        int mtn_tag = 0;
        int mtn_num = 0;

        string[] motion_tags = new string[motion_keys.Count];

        // 読込モーションファイル数カウント用
        foreach (var mtnkey in motion_keys)
        {
            // motions配下のキーを取得
            motion_tags[mtn_tag] = mtnkey.Key.ToString();
            // 読み込むモーションファイル数を取得
            mtn_num += json.get("motions").get(motion_tags[mtn_tag]).getVector(null).Count;
            mtn_tag++;
        }
        // インスタンス化
        mtnFiles     = new TextAsset[mtn_num];
        soundFiles   = new AudioClip[mtn_num];
        mtnFadeines  = new int[mtn_num];
        mtnFadeoutes = new int[mtn_num];

        mtn_tag = 0;
        mtn_num = 0;
        // モーションファイル数分JSON読込
        foreach (var mtnkey in motion_keys)
        {
            // モーションとサウンドを読み込む(motions配下のタグを読み込む)
            Value motionPaths = json.get("motions").get(motion_tags[mtn_tag]);
            int   motionNum   = motionPaths.getVector(null).Count;

            for (int m = 0; m < motionNum; m++)
            {
                mtnFiles[mtn_num] = (Resources.Load(live2Dpath + motionPaths.get(m).get("file").toString()) as TextAsset);
                // サウンドファイルがあれば入れる
                if (motionPaths.get(m).getMap(null).ContainsKey("sound"))
                {
                    // 不要な拡張子を削除
                    string soundnm = Regex.Replace(Regex.Replace(motionPaths.get(m).get("sound").toString(), ".mp3$", ""), ".wav$", "");
                    soundFiles[mtn_num] = (Resources.Load(live2Dpath + soundnm, typeof(AudioClip)) as AudioClip);
                }
                //フェードイン
                if (motionPaths.get(m).getMap(null).ContainsKey("fade_in"))
                {
                    mtnFadeines[mtn_num] = int.Parse(motionPaths.get(m).get("fade_in").toString());
                }
                //フェードアウト
                if (motionPaths.get(m).getMap(null).ContainsKey("fade_out"))
                {
                    mtnFadeoutes[mtn_num] = int.Parse(motionPaths.get(m).get("fade_out").toString());
                }
                mtn_num++;
            }
            mtn_tag++;
        }

        // ポーズファイルを読み込む
        if (json.getMap(null).ContainsKey("pose"))
        {
            Value posepath = json.get("pose");
            poseFile = new TextAsset();
            poseFile = (Resources.Load(live2Dpath + posepath.toString(), typeof(TextAsset)) as TextAsset);
            // pose.jsonを読み込む
            char[] posebuf = poseFile.text.ToCharArray();
            // パーツ切り替えクラスへ渡す
            pose = L2DPose.load(posebuf);
        }

        // 物理演算ファイルを読み込む
        if (json.getMap(null).ContainsKey("physics"))
        {
            Value physicpath = json.get("physics");
            physicsFile = new TextAsset();
            physicsFile = (Resources.Load(live2Dpath + physicpath.toString(), typeof(TextAsset)) as TextAsset);
            // physics.jsonを読み込む
            char[] physicsbuf = physicsFile.text.ToCharArray();
            // 物理演算クラスへ渡す
            physics = L2DPhysics.load(physicsbuf);
        }
    }