public void Load() { var path = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "/avatar.vrm"; if (!File.Exists(path)) { throw new Exception("no file found"); } var data = File.ReadAllBytes(path); var importerContext = new VRMImporterContext(); importerContext.ParseGlb(data); importerContext.Load(); var root = importerContext.Root; importerContext.EnableUpdateWhenOffscreen(); root.GetComponentsInChildren <Renderer>().ToList().ForEach(e => { e.shadowCastingMode = ShadowCastingMode.Off; e.receiveShadows = false; }); var lookAt = root.GetComponent <VRMLookAtHead>(); _humanPoseTransferTarget = root.AddComponent <HumanPoseTransfer>(); _humanPoseTransferTarget.SourceType = HumanPoseTransfer.HumanPoseTransferSourceType.None; lookAt.UpdateType = UpdateType.LateUpdate; //Spring boneのスケジュール SetIK(root, loadSetting); var animator = root.GetComponent <Animator>(); animator.runtimeAnimatorController = animatorController; settingAdjuster.AssignModelRoot(root.transform); var info = new VrmLoadedInfo() { context = importerContext, vrmRoot = root.transform, animator = animator, blendShape = root.GetComponent <VRMBlendShapeProxy>(), }; PreVrmLoaded?.Invoke(info); VrmLoaded?.Invoke(info); }
private void SetModel(GameObject go) { ReleaseCurrentVrm(); if (go == null) { return; } var lookAt = go.GetComponent <VRMLookAtHead>(); _humanPoseTransferTarget = go.AddComponent <HumanPoseTransfer>(); _humanPoseTransferTarget.SourceType = HumanPoseTransfer.HumanPoseTransferSourceType.None; lookAt.UpdateType = UpdateType.LateUpdate; //セットアップのうちFinalIKに思い切り依存した所が別スクリプトになってます VRMLoadControllerHelper.SetupVrm(go, loadSetting); var animator = go.GetComponent <Animator>(); animator.runtimeAnimatorController = animatorController; var blendShapeProxy = go.GetComponent <VRMBlendShapeProxy>(); var renderers = go.GetComponentsInChildren <Renderer>(); foreach (var r in renderers) { //セルフシャドウは明示的に切る: ちょっとでも軽量化したい r.receiveShadows = false; } windowStyleController.InitializeModelRenderers(renderers); settingAdjuster.AssignModelRoot(go.transform); var info = new VrmLoadedInfo() { vrmRoot = go.transform, animator = animator, blendShape = blendShapeProxy, }; PreVrmLoaded?.Invoke(info); VrmLoaded?.Invoke(info); }