コード例 #1
0
    public void CreateTracker(string trackerSerial)
    {
        GameObject prefab         = GetTrackerPrefab(trackerSerial);
        string     gameObjectName = trackerSerial;

        if (prefab != null && gameObjectName != null)
        {
            GameObject go = Instantiate(prefab);
            if (go.tag == "ViveTracker")
            {
                go.GetComponent <ViveTrackerSerialNetwork>().trackerSerial = trackerSerial;
                NetworkServer.Spawn(go);
            }
            go.name = gameObjectName;

            TrackerObject newTracker = new TrackerObject();
            newTracker.gameObject = go;

            trackers.Add(trackerSerial, newTracker);

            Debug.Log("Create tracker " + trackerSerial);

            // tell it to player manager
            PlayerManager.Instance.SetPlayerTrackerObject(trackerSerial, newTracker);
        }
    }
コード例 #2
0
    public void SetPlayerTrackerObject(string trackerSerial, TrackerObject tracker)
    {
        uint id = GetPlayerNetIdFromTrackerSerial(trackerSerial);

        if (id > 0)
        {
            _players[id].tracker = tracker;
        }
    }
コード例 #3
0
 static void FitTrackerObject(TrackerObject proj)
 {
     if (proj.PartList != null)
     {
         Parallel.For(0, proj.PartList.Count, (j) =>
         {
             FitPartsObject(proj.PartList[j]);
         });
     }
 }
コード例 #4
0
 private void Update()
 {
     foreach (KeyValuePair <uint, Player> player in _players)
     {
         Transform     playerTransform = player.Value.playerTransform;
         TrackerObject tracker         = player.Value.tracker;
         if (tracker != null)
         {
             playerTransform.position = tracker.updatedPos;
             playerTransform.rotation = tracker.updatedQuat;
         }
     }
 }
コード例 #5
0
        void Debug_CreateBat(List <NoteListCalculator.NotePreRender> NList, TrackerObject tracker, double BaseTempo)
        {
            //100
            using (FileStream fs = new FileStream(@"D:\\test-t" + tracker.getIndex().ToString() + ".bat", FileMode.Create))
            {
                using (StreamWriter sw = new StreamWriter(fs))
                {
                    sw.WriteLine("mkdir \"%temp%\\utaubk\"");
                    for (int i = 0; i < NList.Count; i++)
                    {
                        //"{RESAMPLEROUTPUT}", "{WAVOUTPUT}");
                        if (NList[i].ResamplerArg != null)
                        {
                            string resStr = String.Join(" ", NList[i].ResamplerArgList);
                            resStr = resStr.Replace("{RESAMPLEROUTPUT}", @"temp$$$.wav");
                            sw.WriteLine(@"D:\VocalUtau\VocalUtau.DebugExampleFiles\UTAUKernel\resampler.exe " + resStr);
                        }
                        string wavStr = String.Join(" ", NList[i].WavtoolArgList);
                        wavStr = wavStr.Replace("{RESAMPLEROUTPUT}", @"temp$$$.wav");
                        wavStr = wavStr.Replace("{WAVOUTPUT}", @"temp.wav");
                        sw.WriteLine(@"D:\VocalUtau\VocalUtau.DebugExampleFiles\UTAUKernel\wavtool.exe " + wavStr);
                    }
                }
            }


            //101
            using (FileStream fs = new FileStream(@"D:\\test-b" + tracker.getIndex().ToString() + ".txt", FileMode.Create))
            {
                using (StreamWriter sw = new StreamWriter(fs))
                {
                    for (int i = 0; i < NList.Count; i++)
                    {
                        //"{RESAMPLEROUTPUT}", "{WAVOUTPUT}");
                        if (NList[i].ResamplerArg != null)
                        {
                            string resStr = String.Join(" ", NList[i].ResamplerArgList);
                            resStr = resStr.Replace("{RESAMPLEROUTPUT}", @"temp$$$.wav");
                            sw.WriteLine(@"resampler.exe " + resStr.Replace(@"D:\VocalUtau\VocalUtau\bin\Debug\voicedb\YongQi_CVVChinese_Version2\", ""));
                        }
                        string wavStr = String.Join(" ", NList[i].WavtoolArgList);
                        wavStr = wavStr.Replace("{RESAMPLEROUTPUT}", @"temp$$$.wav");
                        wavStr = wavStr.Replace("{WAVOUTPUT}", @"temp.wav");
                        sw.WriteLine(@"wavtool.exe " + wavStr.Replace(@"D:\VocalUtau\VocalUtau\bin\Debug\voicedb\YongQi_CVVChinese_Version2\", ""));
                    }
                }
            }
        }
コード例 #6
0
    void HandleMessage(OSCPacket mes)
    {
        //Debug.Log("message received : " + mes.Address.ToString());
        switch (mes.Address.ToString().ToLower())
        {
        case "/iss/tracker":
            string serial = mes.Data[0].ToString();
            if (GetTrackerPrefab(serial) != null)
            {
                if (!trackers.ContainsKey(serial))
                {
                    lock (lockObject)
                    {
                        trackersToCreate.Add(serial);
                    }
                }
                else if (mes.Data.Count >= 8)
                {
                    Vector3 p = new Vector3();
                    p.x = float.Parse(mes.Data[1].ToString());
                    p.y = float.Parse(mes.Data[2].ToString());
                    p.z = float.Parse(mes.Data[3].ToString());

                    Quaternion q = new Quaternion();
                    q.x = float.Parse(mes.Data[4].ToString());
                    q.y = float.Parse(mes.Data[5].ToString());
                    q.z = float.Parse(mes.Data[6].ToString());
                    q.w = float.Parse(mes.Data[7].ToString());

                    int stab = -1;
                    if (mes.Data.Count > 8)
                    {
                        stab = int.Parse(mes.Data[8].ToString());
                    }

                    TrackerObject tObj = trackers[serial];
                    tObj.update(p, q, stab);
                }
            }
            break;

        default:
            break;
        }
    }
コード例 #7
0
        public bool OpenUSTs(Form baseFrom = null)
        {
            FormSpaner.LockFrom(baseFrom);
            FormSpaner.SetFromProcess(0, "查找UST文件", baseFrom);
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter          = "utau工程(*.ust)|*.ust|全部文件(*.*)|*.*";
            ofd.FilterIndex     = 0;
            ofd.CheckFileExists = true;
            ofd.Multiselect     = true;
            if (ofd.ShowDialog(baseFrom) == DialogResult.OK)
            {
                try
                {
                    FormSpaner.SetFromProcess(5, "有效性验证", baseFrom);
                    string[]      FileList = ofd.FileNames;
                    List <string> RealList = new List <string>();
                    for (int i = 0; i < FileList.Length; i++)
                    {
                        if (System.IO.File.Exists(FileList[i]))
                        {
                            RealList.Add(FileList[i]);
                        }
                    }
                    ProjectObject Proj = new ProjectObject();
                    Proj.InitEmpty();
                    Proj.BasicData.IntroduceText   = "";
                    Proj.BasicData.ProjectFilePath = "";
                    Proj.BasicData.SavePassword    = "";
                    Proj.SingerList.Clear();
                    Proj.TrackerList.Clear();
                    Proj.BackerList.Clear();

                    FormSpaner.SetFromProcess(10, "正在装载UST文件", baseFrom);
                    Object thisLock = new Object();
                    Parallel.For(0, RealList.Count, (i) =>
                    {
                        USTOriginalProject USTPO = USTOriginalSerializer.Deserialize(RealList[i]);
                        PartsObject pro          = USTOriginalSerializer.UST2Parts(USTPO);
                        TrackerObject toj        = new TrackerObject((uint)i);
                        toj.Name = pro.PartName;
                        toj.PartList.Clear();
                        toj.PartList.Add(pro);
                        lock (thisLock)
                        {
                            Proj.TrackerList.Add(toj);
                        }
                    });
                    Proj.TrackerList.Sort();
                    FormSpaner.SetFromProcess(90, "正在装载工程文件", baseFrom);
                    LoadProjectObject(ref Proj);
                    FormSpaner.SetFromProcess(100, "完成", baseFrom);
                    FormSpaner.UnLockFrom(baseFrom);
                    tw.Text = "UnsavedProject";
                    return(true);
                }
                catch {; }
            }
            FormSpaner.UnLockFrom(baseFrom);
            return(false);
        }
コード例 #8
0
        public List <NoteListCalculator.NotePreRender> CalcTracker(double TimePosition, TrackerObject tracker, double BaseTempo)
        {
            List <NoteListCalculator.NotePreRender> ResultList             = new List <NoteListCalculator.NotePreRender>();
            Dictionary <int, NoteListCalculator.NotePreRender[]> PreCalcer = new Dictionary <int, NoteListCalculator.NotePreRender[]>();
            Object oLocker = new Object();

            Parallel.For(0, tracker.PartList.Count, (i, ParallelLoopState) =>
            {
                if (tracker.PartList[i].getStartTime() + tracker.PartList[i].getDuringTime() < TimePosition)
                {
                    ParallelLoopState.Break();
                }
                else
                {
                    NoteListCalculator nlc = new NoteListCalculator(SingerDataFinder);
                    nlc.FillPartsNotes(tracker.PartList[i], 0);
                    lock (oLocker)
                    {
                        PreCalcer.Add(i, nlc.NotePreRenderList.ToArray());
                    }
                }
            });
            double DelayTime = TimePosition;
            double TimeState = 0;

            for (int i = 0; i < tracker.PartList.Count; i++)
            {
                PartsObject p        = tracker.PartList[i];
                double      TimeDert = p.getStartTime() - TimeState;
                VocalUtau.Calculators.NoteListCalculator.NotePreRender LastR = null;
                if (TimeDert > 0)
                {
                    long TickRStart = MidiMathUtils.Time2Tick(TimeState, BaseTempo);
                    long TickLength = MidiMathUtils.Time2Tick(TimeDert, BaseTempo);
                    while (TickLength > 0)
                    {
                        VocalUtau.Calculators.NoteListCalculator.NotePreRender npr = new VocalUtau.Calculators.NoteListCalculator.NotePreRender();
                        npr.OtoAtom = new VocalUtau.Formats.Model.Database.VocalDatabase.SoundAtom();
                        npr.OtoAtom.PhonemeSymbol = "{R}";
                        npr.Tick          = TickRStart;
                        npr.Length        = TickLength > 480 ? 480 : TickLength;
                        TickLength       -= 480;
                        TickRStart       += 480;
                        npr.Tempo         = BaseTempo;
                        npr.partStartTime = TimeState;
                        npr.Note          = "{R}";
                        npr.TimeLen       = MidiMathUtils.Tick2Time(npr.Length, BaseTempo) * 1000;
                        LastR             = npr;

                        VocalUtau.Calculators.NoteListCalculator.NotePreRender fn = null;
                        if (PreCalcer.ContainsKey(i))
                        {
                            try
                            {
                                fn = PreCalcer[i][0];
                            }
                            catch {; }
                        }
                        UtauRendCommanderUtils.WavtoolArgs wa = NoteListCalculator.NPR2WavtoolArgs(npr, (TickLength >= 480)?npr:fn, "{RESAMPLEROUTPUT}", "{WAVOUTPUT}");
                        npr.WavtoolArgs    = wa;
                        npr.WavtoolArgList = UtauRendCommanderUtils.GetWavtoolArgs(wa);
                        ResultList.Add(npr);
                    }
                }
                //FixFirstNode
                if (PreCalcer.ContainsKey(i))
                {
                    if (LastR != null)
                    {
                        try
                        {
                            VocalUtau.Calculators.NoteListCalculator.NotePreRender Nxt = PreCalcer[i][0];
                            if (Nxt != null)
                            {
                                if (Nxt.Note != "{R}")
                                {
                                    double PRE       = Nxt.RealPreUtterOverArgs.PreUtterance;
                                    double OVL       = Nxt.RealPreUtterOverArgs.OverlapMs;
                                    double KickFront = PRE - OVL;
                                    double halfNote  = LastR.TimeLen;
                                    if (halfNote < KickFront)
                                    {
                                        //NEED FIX
                                        double ovl = OVL / (PRE - OVL) * halfNote;
                                        double pre = PRE / (PRE - OVL) * halfNote;
                                        if (Nxt.FadeInLengthMs == OVL)
                                        {
                                            Nxt.FadeInLengthMs = ovl;
                                        }
                                        Nxt.RealPreUtterOverArgs.OverlapMs    = ovl;
                                        Nxt.RealPreUtterOverArgs.PreUtterance = pre;
                                        Nxt.StartPoint      = PRE - pre;
                                        Nxt.StartTimeAttend = -Nxt.RealPreUtterOverArgs.OverlapMs / 1000;
                                    }
                                }
                            }
                        }
                        catch {; }
                    }
                    NoteListCalculator.NotePreRender[] LCL = PreCalcer[i];
                    for (int k = 0; k < LCL.Length; k++)
                    {
                        NoteListCalculator.NotePreRender pcr = LCL[k];
                        ResultList.Add(pcr);
                    }
                    TimeState = p.getStartTime() + p.getDuringTime();
                }
            }
            for (int i = 0; i < ResultList.Count; i++)
            {
                double EndTime = ResultList[i].absoluteStartTime * 1000 + ResultList[i].TimeLen;
                if (EndTime == ResultList[i].absoluteStartTime * 1000)
                {
                    long TB = 0;
                }
                if (EndTime < TimePosition * 1000)
                {
                    ResultList.RemoveAt(i);
                    i--;
                }
                else if (ResultList[i].absoluteStartTime < TimePosition)
                {
                    ResultList[i].passTime = (TimePosition - ResultList[i].absoluteStartTime) * 1000;
                }
            }
            //FixFirstNodeEnd
            //  Debug_CreateBat(ResultList, tracker, BaseTempo);
            return(ResultList);
        }