Example #1
0
        public static void Picture2Model()
        {
            XEditorUtil.SetupEnv();
            string name = "";

            float[] args  = new float[CNT];
            float[] args2 = new float[CNT2];
            if (ParseFromPicture(ref args, ref args2, ref name))
            {
                string str   = "";
                int    shape = int.Parse(name[name.Length - 1].ToString());
                for (int i = 0; i < CNT; i++)
                {
                    str += i + "-" + args[i].ToString("f3") + " ";
                }
                Debug.Log(str);
                NeuralData data = new NeuralData
                {
                    callback  = Capture,
                    boneArgs  = args,
                    paintArgs = args2,
                    shape     = (RoleShape)shape,
                    name      = name
                };
                NeuralInput(data, true, true);
            }
        }
Example #2
0
        private static void Update()
        {
            var msg = connect.FetchMessage();

            float[] args1 = new float[CNT];
            float[] args2 = new float[CNT2];
            Array.Copy(msg.param, args1, CNT);
            Array.Copy(msg.param, 95, args2, 0, CNT2);
            if (msg != null)
            {
                NeuralData data = new NeuralData
                {
                    callback  = Capture,
                    boneArgs  = args1,
                    paintArgs = args2,
                    shape     = msg.shape,
                    name      = "neural_" + msg.name
                };
                NeuralInput(data, false, false);
                MoveDestDir("neural_*", "cache/", false);
            }
            if (!connect.Connected)
            {
                EditorApplication.update -= Update;
            }
        }
Example #3
0
        private static void RandomExportModels()
        {
            XEditorUtil.SetupEnv();
            float[]      args = new float[CNT];
            int          expc = 1000;
            FileStream   fs   = new FileStream(EXPORT + "db_description", FileMode.OpenOrCreate, FileAccess.Write);
            BinaryWriter bw   = new BinaryWriter(fs);

            for (int j = 0; j < expc; j++)
            {
                int    shape = UnityEngine.Random.Range(3, 5);
                string name  = string.Format("db_{0:000}_{1}", j, shape);
                bw.Write(name);
                for (int i = 0; i < CNT; i++)
                {
                    args[i] = UnityEngine.Random.Range(0.0f, 1.0f);
                    bw.Write(args[i]);
                }
                NeuralData data = new NeuralData
                {
                    callback = Capture,
                    boneArgs = args,
                    shape    = (RoleShape)shape,
                    name     = name
                };
                UnityEditor.EditorUtility.DisplayProgressBar("database", string.Format("is generating {0}/{1}", j, expc), (float)j / expc);
                NeuralInput(data);
            }
            UnityEditor.EditorUtility.DisplayProgressBar("database", "post processing, wait for a moment", 1);
            bw.Close();
            fs.Close();
            MoveDestDir("db_*", "database/");
            UnityEditor.EditorUtility.ClearProgressBar();
        }
Example #4
0
        private static void NeuralInput(NeuralData data)
        {
            var prev = ScriptableObject.CreateInstance <FashionPreview>();

            prev.NeuralProcess(data);
            FashionPreview.preview = prev;
        }
Example #5
0
 private static void ProcessFile(FileInfo info)
 {
     if (info != null)
     {
         string       file  = info.FullName;
         FileStream   fs    = new FileStream(file, FileMode.Open, FileAccess.Read);
         float[]      args  = new float[CNT];
         BinaryReader br    = new BinaryReader(fs);
         RoleShape    shape = (RoleShape)br.ReadInt32();
         for (int i = 0; i < CNT; i++)
         {
             args[i] = br.ReadSingle();
         }
         NeuralData data = new NeuralData
         {
             callback = Capture,
             boneArgs = args,
             shape    = shape,
             name     = "model_" + info.Name.Replace(".bytes", "")
         };
         NeuralInput(data);
         br.Close();
         fs.Close();
     }
 }
Example #6
0
 public void NeuralProcess(NeuralData data)
 {
     OnEnable();
     this.shape = data.shape;
     CreateAvatar();
     suit_select = UnityEngine.Random.Range(0, fashionInfo.Length - 1);
     DrawSuit();
     Update();
     bone.NeuralProcess(data.boneArgs);
     paint.NeuralProcess();
     data.callback(data.name);
 }
Example #7
0
 private static void NeuralInput(NeuralData data, bool complete, bool repaint)
 {
     if (repaint)
     {
         if (prev != null)
         {
             ScriptableObject.DestroyImmediate(prev); prev = null;
         }
     }
     if (prev == null)
     {
         prev = ScriptableObject.CreateInstance <FashionPreview>();
     }
     prev.NeuralProcess(data, complete);
     FashionPreview.preview = prev;
 }
Example #8
0
 private static void ProcessFile(FileInfo info, bool complete)
 {
     if (info != null)
     {
         float[]    args, args2;
         var        shape = ProcessFile(info, out args, out args2);
         NeuralData data  = new NeuralData
         {
             callback  = Capture,
             boneArgs  = args,
             paintArgs = args2,
             shape     = shape,
             name      = "model_" + info.Name.Replace(".bytes", "")
         };
         NeuralInput(data, complete, true);
     }
 }
Example #9
0
        private static void RandomExportModels(int expc, RoleShape shape, string prefix, bool noise, bool complete)
        {
            XEditorUtil.SetupEnv();
            float[]      args = new float[CNT];
            FileStream   fs   = new FileStream(EXPORT + "db_description", FileMode.OpenOrCreate, FileAccess.Write);
            BinaryWriter bw   = new BinaryWriter(fs);

            bw.Write(expc);
            for (int j = 0; j < expc; j++)
            {
                string name = string.Format("db_{0:00000}_{1}", j, (int)shape);
                bw.Write(name);
                for (int i = 0; i < CNT; i++)
                {
                    args[i] = UnityEngine.Random.Range(0.0f, 1.0f);
                    bw.Write(noise ? AddNoise(args[i], i) : args[i]);
                }
                float[] args2 = new float[CNT2];
                int     r     = UnityEngine.Random.Range(0, 3);
                args2[r] = 1;
                r        = UnityEngine.Random.Range(3, 6);
                args2[r] = 1;
                args2[6] = UnityEngine.Random.Range(0.2f, 0.8f);
                args2[7] = UnityEngine.Random.Range(0.2f, 0.8f);
                for (int i = 0; i < CNT2; i++)
                {
                    bw.Write(args2[i]);
                }
                NeuralData data = new NeuralData
                {
                    callback  = Capture,
                    boneArgs  = args,
                    paintArgs = args2,
                    shape     = shape,
                    name      = name
                };
                UnityEditor.EditorUtility.DisplayProgressBar(prefix, string.Format("is generating {0}/{1}", j, expc), (float)j / expc);
                NeuralInput(data, complete, true);
            }
            UnityEditor.EditorUtility.DisplayProgressBar(prefix, "post processing, wait for a moment", 1);
            bw.Close();
            fs.Close();
            MoveDestDir("db_*", prefix + "_" + shape.ToString().ToLower() + "/");
            UnityEditor.EditorUtility.ClearProgressBar();
        }