private async System.Threading.Tasks.Task onLoadVRMAsync(AvatarSetting setting) { videoCapture.PlayStop(); var path = ""; if (setting.AvatarType == 0) { path = setting.VRMFilePath; } else { path = setting.FBXFilePath; } if (path != "") { //ファイルをByte配列に読み込みます var bytes = File.ReadAllBytes(path); //VRMImporterContextがVRMを読み込む機能を提供します var context = new VRMImporterContext(); // GLB形式でJSONを取得しParseします context.ParseGlb(bytes); // VRMのメタデータを取得 var meta = context.ReadMeta(false); //引数をTrueに変えるとサムネイルも読み込みます //読み込めたかどうかログにモデル名を出力してみる //Debug.LogFormat("meta: title:{0}", meta.Title); //非同期処理(Task)で読み込みます await context.LoadAsyncTask(); /// //読込が完了するとcontext.RootにモデルのGameObjectが入っています var avatarObject = context.Root; avatarObject.name = setting.AvatarName; //モデルをワールド上に配置します avatarObject.transform.SetParent(transform.parent, false); SetVRMBounds(avatarObject.transform); //メッシュを表示します context.ShowMeshes(); setting.Avatar = avatarObject.AddComponent <VNectModel>(); setting.Avatar.ModelObject = avatarObject; setting.Avatar.SetNose(setting.FaceOriX, setting.FaceOriY, setting.FaceOriZ); setting.Avatar.SkeletonMaterial = skeletonMaterial; DiactivateAvatars(); avatars.options.Add(new Dropdown.OptionData(setting.AvatarName)); barracudaRunner.InitVNectModel(setting.Avatar, configurationSetting); } }
void Start() { skeletonMaterial = Resources.Load("Skeleton", typeof(Material)) as Material; barracudaRunner = GameObject.Find("BarracudaRunner").GetComponent <VNectBarracudaRunner>(); barracudaRunner.ModelQuality = configurationSetting.TrainedModel; videoCapture = GameObject.Find("MainTexrure").GetComponent <VideoCapture>(); Menu = GameObject.Find("Menu"); cameraMover = GameObject.Find("MainCamera").GetComponent <CameraMover>(); sourceDevice = GameObject.Find("SourceDevice").GetComponent <Dropdown>(); WebCamDevice[] devices = WebCamTexture.devices; foreach (var d in devices) { sourceDevice.options.Add(new Dropdown.OptionData(d.name)); } sourceDevice.value = 0; btnPause = GameObject.Find("btnPause").GetComponent <Button>(); ifFrame = GameObject.Find("ifFrame").GetComponent <InputField>(); txFrameCount = GameObject.Find("txFrameCount").GetComponent <Text>(); btnSkip = GameObject.Find("btnSkip").GetComponent <Button>(); pnlVideoIF = GameObject.Find("pnlVideoIF"); pnlVideoIF.SetActive(false); btnSourceDevice = GameObject.Find("btnSourceDevice").GetComponent <Button>(); txtFPS = GameObject.Find("txtFPS").GetComponent <Text>(); btnRecord = GameObject.Find("btnRecord").GetComponent <Button>(); avatars = GameObject.Find("Avatars").GetComponent <Dropdown>(); avatarSetting = GameObject.Find("AvatarSetting").GetComponent <AvatarSettingScript>(); avatarSetting.Init(); avatarSetting.gameObject.SetActive(false); configuration = GameObject.Find("Configuration").GetComponent <ConfigurationScript>(); configuration.Init(); configuration.gameObject.SetActive(false); ReflectConfiguration(configurationSetting); var settings = PlayerPrefs.GetString("AvatarSettings", ""); //settings = ""; // Decode Avatar Setting string[] asStr = settings.Split(';'); foreach (var s in asStr) { string[] col = s.Split(','); if (col.Length != 16) { continue; } var setting = new AvatarSetting(); if (!int.TryParse(col[0], out setting.AvatarType)) { continue; } if (setting.AvatarType < 0) { } else if (setting.AvatarType == 0) { setting.VRMFilePath = col[1]; } else if (setting.AvatarType == 1) { setting.FBXFilePath = col[1]; } setting.AvatarName = col[2]; if (!float.TryParse(col[3], out setting.PosX)) { continue; } if (!float.TryParse(col[4], out setting.PosY)) { continue; } if (!float.TryParse(col[5], out setting.PosZ)) { continue; } if (!float.TryParse(col[6], out setting.DepthScale)) { continue; } if (!float.TryParse(col[7], out setting.Scale)) { continue; } if (!float.TryParse(col[8], out setting.FaceOriX)) { continue; } if (!float.TryParse(col[9], out setting.FaceOriY)) { continue; } if (!float.TryParse(col[10], out setting.FaceOriZ)) { continue; } if (!int.TryParse(col[11], out setting.SkeletonVisible)) { continue; } if (!float.TryParse(col[12], out setting.SkeletonPosX)) { continue; } if (!float.TryParse(col[13], out setting.SkeletonPosY)) { continue; } if (!float.TryParse(col[14], out setting.SkeletonPosZ)) { continue; } if (!float.TryParse(col[15], out setting.SkeletonScale)) { continue; } AvatarList.Add(setting); } ; if (AvatarList.Count == 0) { var setting = new AvatarSetting() { AvatarType = -1, AvatarName = "unity-chan", Avatar = GameObject.Find("unitychan").GetComponent <VNectModel>(), }; setting.Avatar.SetNose(setting.FaceOriX, setting.FaceOriY, setting.FaceOriZ); AvatarList.Add(setting); barracudaRunner.InitVNectModel(setting.Avatar); setting = new AvatarSetting() { AvatarType = -2, AvatarName = "yukihiko-chan", Avatar = GameObject.Find("YukihikoAoyagi").GetComponent <VNectModel>(), }; setting.Avatar.SetNose(setting.FaceOriX, setting.FaceOriY, setting.FaceOriZ); AvatarList.Add(setting); barracudaRunner.InitVNectModel(setting.Avatar); } avatars.options.Clear(); foreach (var setting in AvatarList) { if (setting.AvatarType >= 0) { LoadAvatar(setting); } else if (setting.AvatarType < 0) { avatars.options.Add(new Dropdown.OptionData(setting.AvatarName)); switch (setting.AvatarType) { case -1: setting.Avatar = GameObject.Find("unitychan").GetComponent <VNectModel>(); break; case -2: setting.Avatar = GameObject.Find("YukihikoAoyagi").GetComponent <VNectModel>(); break; } setting.Avatar.SetNose(setting.FaceOriX, setting.FaceOriY, setting.FaceOriZ); barracudaRunner.InitVNectModel(setting.Avatar); } } avatars.value = 0; ChangedAvatar(0); }